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

        By Adding the <module name="org.hibernate.validator" /> doesn't seem to help here.

         

        It is still complaining that couldn't find the default provider for validator, which means still couldn't find the org.hibernate.validator from the classpath.

         

        Gary, do you know why we need this dependency? I don't believe our jpa used this.

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

          Jeff Yu wrote:

          Gary, do you know why we need this dependency? I don't believe our jpa used this.

          No sorry, don't know.

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

            Just a comment on what I've found:

             

            In the building EntityManagerFactory, it will trigger a 'BeanValidationIntegrator' object for the 'apply_to_ddl'. It looks like that we can also set this property (hibernate.validator.apply_to_ddl=false) to ignore this validation, I'll try it later and then see if we bypass this error, should everything else starting fine.

             

            However, I've noticed that the 'login' example also trigger the BeanValidationIntegrator, but somehow it doesn't go through the javax.validation.GenericBoostrapImpl.configure() method, while our RiftSaw engine will need to go through this method that will result in the not found the default provider for validator.

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

              Jeff Yu wrote:

               

               

              In the building EntityManagerFactory, it will trigger a 'BeanValidationIntegrator' object for the 'apply_to_ddl'. It looks like that we can also set this property (hibernate.validator.apply_to_ddl=false) to ignore this validation, I'll try it later and then see if we bypass this error, should everything else starting fine.

              By setting the javax.persistence.validation.mode=NONE will remove this dependency, and don't see this error anymore.

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

                My another approach seem to work as well.

                 

                I've copied the hibernate-validator-4.2.0.Final.jar into the bpel component folder, and then adding the following two lines:

                 

                <resources>

                ....

                  <resource-root path="hibernate-validator-4.2.0.Final.jar" />

                </resources>

                <dependencies>

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

                </dependencies>

                 

                With this approach, the previous error was gone as well.

                 

                However, if I've only added the <module name="org.hibernate.validator" />, it won't work.

                 

                Scott, anywhere that I am doing wrong here??

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

                  When you tried depending on module "org.hibernate.validator", what is the exception call stack that you get?

                  • 36. Re: Using JPA/Hibernate from a module
                    sgilda

                    Check out: https://docs.jboss.org/author/display/AS7/Seam+2+Booking+EAR+Migration+of+Binaries+-+Step+by+Step

                    Look for "Next Issue: java.lang.ClassNotFoundException: org.hibernate.validator.InvalidValue" to see the resolution that worked there.

                     

                    Also check out: https://docs.jboss.org/author/display/AS7/How+do+I+migrate+my+application+from+AS5+or+AS6+to+AS7

                    There are a couple of sections that may be helpful:

                    • Configure changes for applications that use Hibernate and JPA
                    • Debug and resolve ClassNotFoundExceptions and NoClassDefFoundErrors
                    • 37. Re: Using JPA/Hibernate from a module
                      jeff.yuchang

                      Scott Marlow wrote:

                       

                      When you tried depending on module "org.hibernate.validator", what is the exception call stack that you get?

                      here is the exception call stack. (as same as the one that I didn't include the 'org.hibernate.validator' in the dependencies)

                       

                      20:37:34,587 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-2) MSC00001: Failed to start service jboss.deployment.unit."say_hello.jar".SwitchYardService: org.jboss.msc.service.StartException in service jboss.deployment.unit."say_hello.jar".SwitchYardService: org.switchyard.exception.SwitchYardException: Failed to initialize the engine: java.lang.Exception: DAO INSTANTIATION FAILED: org.apache.ode.dao.jpa.hibernate.BpelDAOConnectionFactoryImpl , org.apache.ode.dao.jpa.hibernate.ConfStoreDAOConnectionFactoryImpl and org.apache.ode.dao.jpa.hibernate.SchedulerDAOConnectionFactoryImpl

                                at org.switchyard.as7.extension.services.SwitchYardService.start(SwitchYardService.java:90)

                                at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1765)

                                at org.jboss.msc.service.ServiceControllerImpl$ClearTCCLTask.run(ServiceControllerImpl.java:2291)

                                at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [:1.6.0_26]

                                at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [:1.6.0_26]

                                at java.lang.Thread.run(Thread.java:680) [:1.6.0_26]

                      Caused by: org.switchyard.exception.SwitchYardException: Failed to initialize the engine: java.lang.Exception: DAO INSTANTIATION FAILED: org.apache.ode.dao.jpa.hibernate.BpelDAOConnectionFactoryImpl , org.apache.ode.dao.jpa.hibernate.ConfStoreDAOConnectionFactoryImpl and org.apache.ode.dao.jpa.hibernate.SchedulerDAOConnectionFactoryImpl

                                at org.switchyard.component.bpel.deploy.BPELActivator.init(BPELActivator.java:84)

                                at org.switchyard.component.bpel.deploy.BPELActivator.init(BPELActivator.java:95)

                                at org.switchyard.deploy.internal.Deployment.deployServices(Deployment.java:321)

                                at org.switchyard.deploy.internal.Deployment.doStart(Deployment.java:119)

                                at org.switchyard.deploy.internal.AbstractDeployment.start(AbstractDeployment.java:168)

                                at org.switchyard.as7.extension.deployment.SwitchYardDeployment.start(SwitchYardDeployment.java:99)

                                at org.switchyard.as7.extension.services.SwitchYardService.start(SwitchYardService.java:83)

                                ... 5 more

                      Caused by: java.lang.Exception: DAO INSTANTIATION FAILED: org.apache.ode.dao.jpa.hibernate.BpelDAOConnectionFactoryImpl , org.apache.ode.dao.jpa.hibernate.ConfStoreDAOConnectionFactoryImpl and org.apache.ode.dao.jpa.hibernate.SchedulerDAOConnectionFactoryImpl

                                at org.riftsaw.engine.internal.BPELEngineImpl.initDAO(BPELEngineImpl.java:219)

                                at org.riftsaw.engine.internal.BPELEngineImpl.init(BPELEngineImpl.java:107)

                                at org.switchyard.component.bpel.deploy.BPELActivator.init(BPELActivator.java:82)

                                ... 11 more

                      Caused by: javax.persistence.PersistenceException: [PersistenceUnit: ode-bpel] Unable to build EntityManagerFactory

                                at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:903)

                                at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:879)

                                at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:56)

                                at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)

                                at org.apache.ode.dao.jpa.hibernate.BpelDAOConnectionFactoryImpl.init(BpelDAOConnectionFactoryImpl.java:53)

                                at org.apache.ode.il.dbutil.Database.createDaoCF(Database.java:218)

                                at org.riftsaw.engine.internal.BPELEngineImpl.initDAO(BPELEngineImpl.java:212)

                                ... 13 more

                      Caused by: org.hibernate.HibernateException: Error applying BeanValidation relational constraints

                                at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.applyRelationalConstraints(BeanValidationIntegrator.java:186)

                                at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.integrate(BeanValidationIntegrator.java:124)

                                at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:295)

                                at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1720)

                                at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:76)

                                at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:894)

                                ... 19 more

                      Caused by: java.lang.reflect.InvocationTargetException

                                at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_26]

                                at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_26]

                                at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_26]

                                at java.lang.reflect.Method.invoke(Method.java:597) [:1.6.0_26]

                                at org.hibernate.cfg.beanvalidation.BeanValidationIntegrator.applyRelationalConstraints(BeanValidationIntegrator.java:176)

                                ... 24 more

                      Caused by: org.hibernate.HibernateException: Unable to build the default ValidatorFactory

                                at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:376)

                                at org.hibernate.cfg.beanvalidation.TypeSafeActivator.applyDDL(TypeSafeActivator.java:102)

                                ... 29 more

                      Caused by: javax.validation.ValidationException: Unable to find a default provider

                                at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:264)

                                at javax.validation.Validation.buildDefaultValidatorFactory(Validation.java:111)

                                at org.hibernate.cfg.beanvalidation.TypeSafeActivator.getValidatorFactory(TypeSafeActivator.java:373)

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

                        Looks like the information got scattered in this long thread, I'll try to summarise it here.

                         

                        We have the RiftSaw modules inside switchyard (AS 7), they have been put in the $AS7/modules/org/switchyard/component/bpel/main , once the switchyard (AS7) started, the RiftSaw service is not started yet, this is a lazy service, only got activated when it detects an RiftSaw(Bpel) artifact.

                         

                        And then we deploy the say_hello.jar (a RiftSaw/Bpel artifact) into the $AS7/standalone/deployment folder, then the RiftSaw service got activated, where we will see the exception. (either 'No Persistence provider for EntityManager named ode-bpel' or 'javax.validation.ValidationException: Unable to find a default provider').

                         

                        Below is the code snippet that trigger the EntityManagerFactory initialisation.

                         

                        {code}         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());              return cf;          } finally {               //Thread.currentThread().setContextClassLoader(old);          } {code}

                         

                        Following are some attempts and its results.

                         

                        1) if we've used the above code, which means didn't change the classloader, it will have following information

                          '20:47:18,570 INFO  [org.hibernate.ejb.Ejb3Configuration] (MSC service thread 1-1) HHH00318:Could not find any META-INF/persistence.xml file in the classpath

                           I've debug inside hibernate, and found the Thread.currentThread().getClassLoader() is the 'deployment/say_hello.jar', therefore it couldn't locate the META-INF/persistence.xml inside $AS7/module/org/switchyard/component/bpel/main/riftsaw-dao-jpa.jar

                         

                        2) And then we've set the classloader to getClass().getClassLoader(). (basically just remove the above two comments line), now it could locate the META-INF/persistence.xml. However, at this time, it throws the 'javax.validation.ValidationException: Unable to find a default provider' exception, it looks like couldn't find the hibernate-validator.jar that is located in $AS7/modules/org/hibernate/validator folder. Whether I've specified the dependency inside the module.xml or not, the exception remains the same.

                         

                        3) After we've added the org.hibernate.validator dependency in module.xml, copied the hibernate-validator.jar into component/bpel/main folder, and then add the hibernate-validator into resource-root of module.xml as well. Everything working fine now.

                         

                        So the 3rd one is quite a dirty hack, any other approaches that I can make it work?

                         

                        @Scott, as you said, the JPA service seem to be started as late as possible in AS 7.0.1, should we file a jira request that we need to specify our riftsaw service depends on JPA service somehow, so it can be make sure the JPA service got started properly before RiftSaw service. Or is this already doable?

                         

                        Hopefully the summary describe the problem clearer, if not, please let me know.

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

                          Are you obtaining the EntityManagerFactory during RiftSaw service start?  Or is the EntityManagerFactory obtained at deployment time of say_hello.jar (RiftSaw/Bpel)?

                           

                          On the other question/issue, if needed, I can expose enough information about the JPA service so that you could depend on it.  I already have a local change to SPI access to the JPA service name but I need to API it, for you to depend on it.  I would need a Jira for this change.  You may as wait until getting past the ValidationException (in case its not needed after solving that).

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

                            Just talked with Stuart Douglas about this issue (Thanks Stuart), and then he told me that by specifying the hibernate validator dependencies, we need to add the   services="import" to make sure that the 'hibernate-validator/META-INF/services/javax.validation.spi.ValidationProvider" got added into the classloader, following is the complete line for validator module dependency. In case anyone wants the detail explanation the module descriptor, here it is (https://docs.jboss.org/author/display/MODULES/Module+descriptors).

                             

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

                             

                            Once I've added above line, the ValidationException was gone.

                             

                            Thanks Scott and all.

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

                              Scott Marlow wrote:

                               

                              Are you obtaining the EntityManagerFactory during RiftSaw service start?  Or is the EntityManagerFactory obtained at deployment time of say_hello.jar (RiftSaw/Bpel)?

                               

                              We obtained the EntityManagerFactory during the RiftSaw service start.

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

                                I think this leaves us with just the question of how to ensure that the RiftSaw service starts after the JPA service.  So that RiftSaw can depend on the JPA service to load the Hibernate persistence provider before javax.persistence.Persistence.createEntityManagerFactory is called.  Can you create an AS 7.1 (JPA) jira for that. 

                                 

                                A related jira, is AS7-1864, which requests that we eagerly load the Hibernate persistence provider during AS7 startup.

                                • 43. Re: Using JPA/Hibernate from a module
                                  jeff.yuchang
                                  • 44. Re: Using JPA/Hibernate from a module
                                    smarlow

                                    Jiras AS7-1864 + AS7-1869 are both fixed in AS7 master (AS 7.1 will have the fix as will tomorrows night build http://community.jboss.org/thread/167590). 

                                    1 2 3 Previous Next