views:

53

answers:

1
Hi guys, I am trying to create a new JEE project using hibernate and JPA 2.0 on the glass fish server.Can you guys provide me some resources to configure the above so that they work seemlessly. I have tried using netbeans and generated the persistence unit by using the hibernate provider,but i end up getting this error javax.persistence.PersistenceException: [PersistenceUnit: DBAppPU] Unable to build EntityManagerFactory I am new to all this technologies so i am looking for good resource to learn also.Your help will be greatly appreciated :) Thanks!
+1  A: 

First, install Hibernate support via the update tool (or follow the manual procedure). Second, provide a JPA 2.0 persistence.xml to use Hibernate as JPA provider:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">
  <persistence-unit name="MyPu" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <!-- JNDI name of the database resource to use -->
    <jta-data-source>jdbc/__default</jta-data-source>
    <properties>
      <!-- The database dialect to use -->
      <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect" />
      <!-- update database tables at deployment -->
      <property name="hibernate.hbm2ddl.auto" value="update"/>
      <!-- log the generated SQL -->
      <property name="hibernate.show_sql" value="true"/>
    </properties>
  </persistence-unit>
</persistence>

Resources

Pascal Thivent
Thanks pascal, you are a true guru.I just realized that the hibernate libraries should be put on the servers folder.
BinCode
Now i dont get any error but nothing turns up in the display .On checking the logs i see the followingNot binding factory to JNDI, no JNDI name configured
BinCode
@BinCode Did you configure a particular datasource? What is its JNDI name? Could you test it successfully in the admin console? Also please show your `persistence.xml`.
Pascal Thivent
i have added my files below please check and let me know what am i doing wrong thanks.
BinCode
Assistance required :D
BinCode
@BinCode I'll take a look at your problem but please open a new question. My answer covered your initial question. The current problem (even if related) is a new one and it's a best practice to not mix problems in a question (on top of that, my answer now looks odd now). So please open a new question and revert the body of this one to the one of the first revisions.
Pascal Thivent
Sure will do that Thanks!
BinCode