1 Reply Latest reply on Dec 2, 2010 7:08 AM by wdfink

    Unable to build EntityManagerFactory with netbeans

    lolveley

      hello,

       

      my problem concerns the link between an EJB session 3.0 and a persistence layer : JPA entities.

       

      I use fedora 14, the computer's name is "vetiver" (name that I use for mysql e.g. in the "host" property), the IDE is netbeans 6.9.1.

       

      here is the error :

       

       

      Exception in thread "main" javax.ejb.EJBException: javax.persistence.PersistenceException: [PersistenceUnit: PAM_3_ejb_jndiPU] Unable to build EntityManagerFactory

      in the line 34 of the file MyBean.java :

       

      @Stateless
      public class MyBean implements MyBeanRemote, MyBeanLocal {
      
          private EntityManagerFactory factory = null;
      
          public String sayHello() {
              return "Hello there";
          }
      
          // Add business logic below. (Right-click in editor and choose
          // "Insert Code > Add Business Method")
          public String save() {
      
              factory = Persistence.createEntityManagerFactory("PAM_3_ejb_jndiPU"); //<-- line 34
              EntityManager em = factory.createEntityManager();
              em.persist(new Employes("174012345678901"));
              em.flush();
              em.close();
              factory.close();
              return "It works!!";
      
          }
      }
      

       

      here is some interesting stuff : the file capture2.jpg, linked to this post.

      you can see the libraries used by the project that contains the bean.

       

      here is the persistence.xml file :

       

       

      <?xml version="1.0" encoding="UTF-8"?>
      <persistence version="1.0" 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_1_0.xsd">
        <persistence-unit name="PAM_3_ejb_jndiPU" transaction-type="JTA">
          <provider>org.hibernate.ejb.HibernatePersistence</provider>
          <jta-data-source>java:/tutoriel3</jta-data-source>
          <class>jpa.Cotisations</class>
          <class>jpa.Employes</class>
          <class>jpa.Indemnites</class>
          <exclude-unlisted-classes>false</exclude-unlisted-classes>
          <properties>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
            <property name="hibernate.c3p0.min_size" value="5"/>
            <property name="hibernate.c3p0.max_size" value="20"/>
            <property name="hibernate.c3p0.timeout" value="300"/>
            <property name="hibernate.c3p0.max_statements" value="50"/>
            <property name="hibernate.c3p0.idle_test_period" value="3000"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
            <property name="hibernate.connection.url" value="jdbc:mysql://vetiver:3306/tutoriel3"/>
            <property name="hibernate.connection.username" value="lolveley"/>
            <property name="hibernate.connection.password" value="***"/>
            <property name="hibernate.archive.autodetection" value="class, hbm"/>
           
            <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
          </properties>
        </persistence-unit>
      </persistence>
      

       

       

       

      tell me if you want some extra infos.

       

      thanks,

       

      olivier.