1 2 3 Previous Next 44 Replies Latest reply on Oct 5, 2011 9:52 AM by smarlow Go to original post
      • 15. Re: Using JPA/Hibernate from a module
        smarlow

        What classes are in riftsaw-dao-jpa-3.0.0-SNAPSHOT.jar +

        riftsaw-dao-jpa-hibernate-3.0.0-SNAPSHOT.jar?  Does that contain your own copy of the Hibernate jars and javax.persistence?

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

          In the riftsaw-dao-jpa class it just contains the DAO implementation classes. In the -hibernate jar it contains connection factory impl and datasource connection provider. They don't contain any hibernate or javax.persistence classes, these are only picked up using the module dependency on "org.hibernate" and "javax.persistence.api".

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

            I think setting a breakpoint in javax.persistence.Persistence.createEntityManagerFactory() and javax.persistence.spi.PersistenceProviderResolverHolder.setPersistenceProviderResolver() would explain a lot.  Also set a breakpoint in javax.persistence.spi.PersistenceProviderResolverHolder.getPersistenceProviderResolver().

             

            When the call to javax.persistence.spi.PersistenceProviderResolverHolder.setPersistenceProviderResolver() occurs, make note of the PersistenceProviderResolverHolder.class.getClassLoader() value.

             

            Later, when the call to javax.persistence.Persistence.createEntityManagerFactory() from your  application occurs (for the call expected to fail), note the PersistenceProviderResolverHolder.class.getClassLoader() value again (should also match the Persistence.class.getClassLoader()). 

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

              You might be able to get the same information by using Byteman (if someone wants to explain how to use Byteman on AS7 ;).

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

                Ok thanks, sorry for the delay - been investigating another issue. Either Jeff or I will get the info to you for Monday.

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

                  I am not sure if I am doing something wrong here or not. I am using the remote debug (by uncommenting the standalone.conf 8787 port), found that the javax.persistence.spi.PersistenceProviderResolverHolder.setPersistenceProviderResolver() method never got called in my debug.

                   

                  I am only able to catch it in the javax.persistence.spi.PersistenceProviderResolverHolder.getPersistenceProviderResolver(). Following is some properties and corresponding value. The value is same when I was doing the login example deployment and the riftsaw engine starting.

                   

                  PersistenceProviderResolverHolder.class.getClassLoader() => ModuleClassLoader for Module "javax.persistence.api:main" from local module loader @6a969c29 (roots: /Users/jeffyu/deploy/switchyard-as7-0.3/modules)

                  RESOLVER => org.jboss.as.jpa.persistenceprovider.PersistenceProviderResolverImpl@64617029

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

                    It might help if you force the AS7 boot to wait until you have attached your debugger.  To do this, "set suspend=y".

                    JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=y"

                     

                    Could you look at the org.jboss.as.jpa.persistenceprovider.PersistenceProviderResolverImpl.providers list as well.  I would expect that after running the (Login) sample application, that the Hibernate persistence provider would be in the list and that deploying the RiftSaw should see it.

                     

                    If that is true, we will have enough information for making an AS7 code change to improve this situation.  The anticipated solution being to pre-load the default persistence provider (Hibernate 4) during boot (will need a AS7 JPA jira for that change).  If not, lets continue to explore why not.

                     

                    Scott

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

                      Yes, the providers list had the org.hibernate.ejb.HibernatePersistence@732e3e73 object.

                       

                      Does it mean that the JPA service hasn't been started properly? With login sample application, I would expect the JPA service should be started properly, but why it still complains that couldn't find the Persistence Provider when Deploying the RiftSaw?

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

                        After the login sample application completes and you deploy the RiftSaw, could you then step through the javax.persistence.Persistence.createEntityManagerFactory() to see what is going wrong? 

                         

                        It will be interesting to know why its not using the org.hibernate.ejb.HibernatePersistence instance already used by the login sample application.

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

                          I believe I may find the culprit. The HibernatePersistence instance was used correctly. It is in the Ejb3Configuration.configure(...) method, which is using following code the find the META-INF/persistence.xml file.

                           

                                                        Enumeration<URL> xmls = Thread.currentThread()

                                                                            .getContextClassLoader()

                                                                            .getResources( "META-INF/persistence.xml" );

                           

                          It returns an empty Enumeration. Looks like above code doesn't find the persistence.xml inside the dao-jpa/META-INF/persistence.xml somehow.

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

                            In that code, what does the following expression evaluate to?

                            Thread.currentThread().getContextClassLoader()

                             

                            If your debugging in intellij, right mouse button click over the source file and from the menu choose "evalute expression...".  You can then enter the above expression and evaluate it.  The result will be shown.  You probably know this already.

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

                              The value is:  ModuleClassLoader for Module "deployment.say_hello.jar:main" from Service Module Loader

                               

                              The say_hello.jar is the bpel's artifact, once it gets deployed in the deployment folder, it will trigger the RiftSaw service start, and then do the deployment etc.

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

                                Now, I've updated the classloader that created the EMF with following change.

                                 

                                        ClassLoader old = Thread.currentThread().getContextClassLoader();

                                        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());

                                        BpelDAOConnectionFactory cf;

                                        try {

                                                  try {

                                                      cf = (BpelDAOConnectionFactory) Class.forName(pClassName).newInstance();

                                                  } catch (Exception ex) {

                                                      String errmsg = __msgs.msgDAOInstantiationFailed(pClassName);

                                                      __log.error(errmsg, ex);

                                                      throw new DatabaseConfigException(errmsg, ex);

                                                  }

                                 

                                                  cf.init(_odeConfig.getProperties(),_txm,getDataSource());

                                              } finally {

                                                        Thread.currentThread().setContextClassLoader(old);

                                              }

                                        return cf;

                                 

                                Originally, we didn't set the Thread.currentThread.ContextClassLoader as getClass().getClassLoader(). Then I was getting that the 'META-INF/persistence.xml' didn't found. After I've done the above change, this error was gone. However, I've now seen a new exception. https://gist.github.com/1219203

                                 

                                What could it be wrong here? I've attached the server.log file here.

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

                                  Sounds like say_hello.jar had the Hibernate Validator dependency defined but the classloader returned from getClass().getClassLoader(), does not have as many needed dependencies defined.

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

                                    The say_hello.jar only contained a bpel process, some wsdl files and the switchyard.xml, so it wouldn't have had the validator dependency.

                                     

                                    However just looking at the switchyard-component-bpel/src/build/resources/module.xml, it has the module dependency on "org.hibernate" but the validator is actually defined in a separate module.

                                     

                                    So Jeff, could you edit the module.xml and add the line:

                                     

                                           <module name="org.hibernate.validator"/>

                                     

                                    after the existing org.hibernate entry and rebuild the component, and the rebuild the as7 distribution. Hopefully that should resolve this issue.