4 Replies Latest reply on Nov 13, 2007 4:05 PM by darretta

    Persistence Problem with Jboss 4.0.3, Hibernate

    darretta

      I'm a persistence/EJB 3 newbie having difficulties initializing my EntityManagerFactory. The error I'm getting is the infamous "No Persistence provider for Entity Manager "....

      Here is my setup:

      * JBoss 4.0.3SP1

      * PostgreSQL 8.2.4

      * Hibernate persistence

      * Deployed EAR:

      vram.ear
       |
       -- vram-ejbs.jar
       |
       -- hibernate.properties
       -- META-INF/persistence.xml


      * persistence.xml
      <persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
       <persistence-unit name="vramPu">
       <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/nicweb/DataSource</jta-data-source>
       </persistence-unit>
       <properties>
       <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
       <property name="hibernate.show_sql" value="true"/>
       </properties>
      </persistence>


      * hibernate.properties
      hibernate.dialect org.hibernate.dialect.PostgreSQLDialect
      hibernate.connection.driver_class org.postgresql.Driver
      hibernate.connection.url jdbc:postgresql://localhost/nicweb
      hibernate.connection.username nicweb-admin
      hibernate.connection.password nicweb-admin

      * EJB Stateless Session Bean
      @Stateless
      public class MyClass implements MyClassRemote {
      
       @PersistenceContext
       private EntityManager em;
      
       @PersistenceUnit
       private EntityManagerFactor emf;
      
       ...
      
       /* Error thrown at this call... */
       emf = Persistence.createEntityManagerFactory("vramPu");
       em = emf.createEntityManager();



      I think the Persistence API is able to locate the persistence.xml file, and the hibernate.properties is loaded (but not sure if needed).

      Any help is greatly appreciated.

      Regards,
      Mike




        • 1. Re: Persistence Problem with Jboss 4.0.3, Hibernate
          darretta

          I have since removed hibernate.properties...still no joy.

          • 2. Re: Persistence Problem with Jboss 4.0.3, Hibernate
            jaikiran

            Please post the appropriate part of the logs along with the exception stacktrace.

            • 3. Re: Persistence Problem with Jboss 4.0.3, Hibernate
              darretta

              In gathering the requested logs, I noticed for the first time this message:

              Persistence unit name: vram-dos-server-ejbs-CURRENT

              This is the actual name of my EJB jar file, not my persistence unit name configured in persistence.xml. I changed my code to reference this name, and everything works! I do have a new persistence.xml file as well (though I don't think this changed anything). Below is the file. I you have any thoughts as to why the persistence unit name is my jar file name and not the name given in the XML file, that would be helpful. Thanks!

              <?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="vramPu">
               <provider>org.hibernate.ejb.HibernatePersistence</provider>
               <jta-data-source>java:/nicweb/DataSource</jta-data-source>
               <jar-file>vram-dos-server-ejbs-CURRENT.jar</jar-file>
               <properties>
               <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvider"/>
               </properties>
               </persistence-unit>
              </persistence>
              


              • 4. Re: Persistence Problem with Jboss 4.0.3, Hibernate
                darretta

                Upgraded to RC5 and problem resolved.