1 2 3 Previous Next 44 Replies Latest reply on Oct 5, 2011 9:52 AM by smarlow

    Using JPA/Hibernate from a module

    objectiser

      Hi

       

      I'm building a component for switchyard for deployment in AS7, where the component is delivered as an AS7 module. One of the jars in this module has a persistence.xml.

       

      The problem is that I am getting an exception:

       

      javax.persistence.PersistenceException: No Persistence provider for EntityManager named ode-bpel

          at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:69) [hibernate-jpa-2.0-api-1.0.1.Final.jar:1.0.1.Final]

       

      The default build for switchyard currently uses AS7.0.0.Final as its base, although I have also tried it with 7.0.1.Final, due to the changes to support hibernate 3 and 4.

       

      With AS7.0.0.Final, the error was preceded by:

       

      16:00:44,188 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-2) HHH00318:Could not find any META-INF/persistence.xml file in the classpath
      

       

      so appeared to be classpath related due to module isolation. Not sure if anything special is required to enable JPA to locate the persistence.xml file in the module?

       

      The module dependencies include....

       

      <dependencies>
              <module name="org.hibernate"/>
              <module name="org.jboss.as.jpa"/>
              <module name="javax.api"/>
              <module name="javax.transaction.api"/>
              <module name="javax.persistence.api"/>
              ....
      

       

      When I build against AS7.0.1.Final, I also added the module dependency "org.jboss.as.jpa.hibernate" slot "4". This resulted in the same exception, but this time the "Could not find any META-INF/persistence.xml file in the classpath" message was not present.

       

      So not sure if the AS7.0.1 run is now finding the persistence.xml and there is another problem, or whether locating the xml file is still the problem?

       

      Any suggestions appreciated.

       

      Regards

      Gary

        • 1. Re: Using JPA/Hibernate from a module
          smarlow

          Please attach your as7/standalone/log/server.log from running with AS 7.0.1. 

          • 2. Re: Using JPA/Hibernate from a module
            objectiser

            Done, just in case you didn't get notification of the attachment being added. Sorry for the log size, but thought best to run with TRACE level on to see the class loading activity.

            • 3. Re: Using JPA/Hibernate from a module
              smarlow

              I see the exception call stack, which I pasted to http://pastebin.com/NC4p36u0 for future reference.

               

              What are your persistence.xml contents? 

              • 4. Re: Using JPA/Hibernate from a module
                objectiser

                The persistence.xml in the riftsaw-dao-jpa-3.0.0-SNAPSHOT.jar is:

                 

                <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="ode-bpel" transaction-type="JTA">

                        <mapping-file>META-INF/riftsaw-orm.xml</mapping-file>

                        <class>org.apache.ode.dao.jpa.bpel.ActivityRecoveryDAOImpl</class>

                        <class>org.apache.ode.dao.jpa.bpel.CorrelationSetDAOImpl</class>

                        <class>org.apache.ode.dao.jpa.bpel.CorrelatorDAOImpl</class>

                        <class>org.apache.ode.dao.jpa.bpel.EventDAOImpl</class>

                        <class>org.apache.ode.dao.jpa.bpel.FaultDAOImpl</class>

                        <class>org.apache.ode.dao.jpa.bpel.MessageDAOImpl</class>

                        <class>org.apache.ode.dao.jpa.bpel.MessageExchangeDAOImpl</class>

                        <class>org.apache.ode.dao.jpa.bpel.MessageRouteDAOImpl</class>

                        <class>org.apache.ode.dao.jpa.bpel.PartnerLinkDAOImpl</class>

                        <class>org.apache.ode.dao.jpa.bpel.ProcessDAOImpl</class>

                        <class>org.apache.ode.dao.jpa.bpel.ProcessInstanceDAOImpl</class>

                        <class>org.apache.ode.dao.jpa.bpel.ScopeDAOImpl</class>

                        <class>org.apache.ode.dao.jpa.bpel.XmlDataDAOImpl</class>

                        <class>org.apache.ode.dao.jpa.bpel.CorrSetProperty</class>

                        <class>org.apache.ode.dao.jpa.bpel.MexProperty</class>

                        <class>org.apache.ode.dao.jpa.bpel.XmlDataProperty</class>

                        <class>org.jboss.bpm.monitor.model.bpaf.Event</class>

                        <class>org.jboss.bpm.monitor.model.bpaf.Tuple</class>

                    </persistence-unit>

                    <persistence-unit name="ode-store" transaction-type="JTA">

                        <mapping-file>META-INF/riftsaw-ode-store.xml</mapping-file>

                        <class>org.apache.ode.dao.jpa.store.ProcessConfDaoImpl</class>

                        <class>org.apache.ode.dao.jpa.store.ProcessConfPropertyDaoImpl</class>

                        <class>org.apache.ode.dao.jpa.store.DeploymentUnitDaoImpl</class>

                        <class>org.apache.ode.dao.jpa.store.VersionTrackerDAOImpl</class>

                    </persistence-unit>

                    <persistence-unit name="ode-scheduler" transaction-type="JTA">

                      <class>org.apache.ode.dao.jpa.scheduler.JobDAOImpl</class>

                    </persistence-unit>

                </persistence>

                • 5. Re: Using JPA/Hibernate from a module
                  smarlow

                  With AS 7.0, I'm surprised you got this exception.  Your initialization code probably ran before the hibernate module was loaded, is my guess with 7.0.  With 7.0.1, we are loading the Hibernate module, as late as possible.  So, its not a huge suprise.

                   

                  Do you always obtain the EntityManagerFactory via a call to javax.persistence.Persistence.createEntityManagerFactory?

                  • 6. Re: Using JPA/Hibernate from a module
                    jeff.yuchang

                    Scott Marlow wrote:

                     

                    Do you always obtain the EntityManagerFactory via a call to javax.persistence.Persistence.createEntityManagerFactory?

                    Yes, but we've only created the EMF once, and then we've created the EM, which is attached at the ThreadLocal.

                     

                    Regards

                    Jeff

                    • 7. Re: Using JPA/Hibernate from a module
                      smarlow

                      We can either make SwitchYard more independent of the AS7 JPA module or we could have the

                      org.switchyard.as7.extension.services.SwitchYardService service depend on the org.jboss.as.jpa.service.JPAService service. 

                       

                      Even if switchyard depends on the AS7 JPA service, some code changes are probably needed for loading the Hibernate 4 module earlier. 

                       

                      A few other observations, your persistence.xml doesn't specify which persistence provider you want to use.  That seems to work well with the javax.persistence.Persistence.createEntityManagerFactory, which doesn't check the requested provider (just returns the first one found).

                       

                      Do you guys need to work with Hibernate 3.x also?  Hibernate 4.0 is what we expect to see used in production with AS7.  I'd like to hear now about any need for Hibernate 3.x.

                      • 8. Re: Using JPA/Hibernate from a module
                        jeff.yuchang

                        Scott Marlow wrote:

                         

                        A few other observations, your persistence.xml doesn't specify which persistence provider you want to use.  That seems to work well with the javax.persistence.Persistence.createEntityManagerFactory, which doesn't check the requested provider (just returns the first one found).

                        We didn't specify it in the persistence.xml, however, we've passed the property in when we create the EntityManagerFactory.  like props.put("javax.persistence.provider", "org.hibernate.ejb.HibernatePersistence"); The reason for doing so is that Apache ODE are supporting two JPA impl, (OpenJPA and Hibernate), hence we can't put it inside the persistence.xml file.

                         

                        Scott Marlow wrote:

                         

                        Do you guys need to work with Hibernate 3.x also?  Hibernate 4.0 is what we expect to see used in production with AS7.  I'd like to hear now about any need for Hibernate 3.x.

                        We are fine with Hibernate 4.0 only, however, it would be good that can work well with hibernate 3.x, we orignally was using Hibernate 3.3.2.GA. We've used the approach that you described in your blog entry about using Hibernate 3.x, as Gary pointed out, we were seeing the same exception after we've upgraded to Hibernate 4.0.

                        • 9. Re: Using JPA/Hibernate from a module
                          smarlow

                          I see two possible paths forward from here.

                           

                          1. Don't get the EntityManagerFactory until the AS7 server has completed startup and a SwitchYard application has need of an EntityManager.  I probably need to make a JPA code change to arrange for the Hibernate:4 module to be loaded during startup or give you a way to request that I load it.
                          2. Work out the steps needed for SwitchYard to depend on the JPA service that I mentioned above.  I still need to help you get the Hibernate:4 module loaded or give you a way to request Hibernate to be loaded by the JPA service.
                          • 10. Re: Using JPA/Hibernate from a module
                            jeff.yuchang

                            Just for hack, I've deployed the Login example (CDI + JPA + EJB + JTA + JSF) into AS7, it is working fine. And then I've deployed the RiftSaw's artifact, which will result in starting the RiftSaw Engine, creating EMF etc. But it has the same exception. I believe with the login example deployed, it should loaded the Hibernate module, however, still same error, was it possible any other issues?

                            • 11. Re: Using JPA/Hibernate from a module
                              smarlow

                              Sure, it could be different than I think.  Could you attach the as7/standalone/log/server.log (please don't enable trace logging).

                              • 12. Re: Using JPA/Hibernate from a module
                                jeff.yuchang

                                Sure, here it is the server.log file. And just in case we did something wrong in module.xml, here it is the module.xml content. https://gist.github.com/1205495

                                 

                                Thanks

                                Jeff

                                • 13. Re: Using JPA/Hibernate from a module
                                  objectiser

                                  Just to clarify a point, with our current tests we deploy the bpel switchyard app after the server has started, so don't think the jpa service is an issue here (regarding this exception). But eventually the apps will already be deployed when the server is starting up, so the service dependency issue will probably need to be sorted out.

                                  • 14. Re: Using JPA/Hibernate from a module
                                    jeff.yuchang

                                    Instead of creating the EMF from the persistence.xml file, I've used the Ejb3Configuration class the programmatically configure the entities, and it is working fine. So it means it is still having issue on the classpath/classloader area.

                                     

                                    I've created the EMF in the dao-jpa-hibernate jar, while I've put the persistence.xml inside the dao-jpa.jar!/META-INF. Although I've manually changed it to the dao-jpa-hibernate!/META-INF/persistence.xml, it is still not working... looks like somehow the META-INF/persistence.xml couldn't be picked up.

                                    1 2 3 Previous Next