14 Replies Latest reply on Jul 19, 2016 9:43 AM by fharms

    Problem with Wildfly 8.2 and JPA 2.1

    fharms

      Folks,


      I’m doing a bit of legacy hacking someone would say. The short story is I’m trying to make Wildfly 8.2 work with JPA 2.1 & Hibernate 4.3.11.Final. My initial plan was to use Hibernate 5.2 but didn’t have much luck, so decided to go with a version closer to the one shipped with Wildfly 8 and later with a new version.


      So far I have created a custom Hibernate modules containing the relevant API’s for JPA2.1 and jar files. Created a Arquillian test for testing it work as expected, but get an error when Hibernate is running it’s configuration step.


      Any idea why I get an ClassCastException, classloader issue or is it even possible?


      Thanks!


      18:06:37,870 INFO  [org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory] (ServerService Thread Pool -- 23) HHH000397: Using ASTQueryTranslatorFactory
      18:06:37,871 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool -- 23) MSC000001: Failed to start service jboss.persistenceunit."jpa2wildfly.war#hibernate52Pu": org.jboss.msc.service.StartException in service jboss.persistenceunit."jpa2wildfly.war#hibernate52Pu": org.hibernate.HibernateException: could not instantiate QueryTranslatorFactory: org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory
        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:172) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:117) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
        at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.8.0_51]
        at org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:474)
        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:182) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_51]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_51]
        at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_51]
        at org.jboss.threads.JBossThread.run(JBossThread.java:122)
      Caused by: org.hibernate.HibernateException: could not instantiate QueryTranslatorFactory: org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory
        at org.hibernate.cfg.SettingsFactory.createQueryTranslatorFactory(SettingsFactory.java:508) [hibernate-core-4.3.11.Final.jar:4.3.11.Final]
        at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:264) [hibernate-core-4.3.11.Final.jar:4.3.11.Final]
        at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2444) [hibernate-core-4.3.11.Final.jar:4.3.11.Final]
        at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2440) [hibernate-core-4.3.11.Final.jar:4.3.11.Final]
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1857) [hibernate-core-4.3.11.Final.jar:4.3.11.Final]
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:852)
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:845)
        at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:398) [hibernate-core-4.3.11.Final.jar:4.3.11.Final]
        at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:844)
        at org.jboss.as.jpa.hibernate4.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:44)
        at org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:154) [wildfly-jpa-8.2.0.Final.jar:8.2.0.Final]
        ... 8 more
      Caused by: java.lang.ClassCastException: org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory cannot be cast to org.hibernate.hql.spi.QueryTranslatorFactory
        at org.hibernate.cfg.SettingsFactory.createQueryTranslatorFactory(SettingsFactory.java:503) [hibernate-core-4.3.11.Final.jar:4.3.11.Final]
        ... 18 more
      


      jboss-deployment-structure.xml


      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2">
         <deployment>
             <exclusions>
                 <module name="org.hibernate" />
                 <module name="org.hibernate.envers" />
                 <module name="org.hibernate.commons-annotations" />
             </exclusions>
             <dependencies>
                 <module name="javax.api" slot="4.3.11.Final"/>
                 <module name="javax.annotation.api" slot="4.3.11.Final"/>
                 <module name="javax.enterprise.api" slot="4.3.11.Final"/>
                 <module name="javax.persistence.api" slot="4.3.11.Final"/>
                 <module name="javax.transaction.api" slot="4.3.11.Final"/>
                 <module name="javax.validation.api" slot="4.3.11.Final"/>
                 <module name="org.hibernate" slot="4.3"/>
             </dependencies>
         </deployment>
      </jboss-deployment-structure>
      


      The custom module is build on the javax modules from Wildfly 9 and the Hibernate 4.3.11.Final


      .
      |____com
      | |____fasterxml
      | | |____classmate
      | | | |____4.3.11.Final
      | | | | |____classmate-1.1.0.jar
      | | | | |____module.xml
      | | |____jackson
      | | | |____core
      | | | | |____jackson-annotations
      | | | | | |____4.3.11.Final
      | | | | | | |____jackson-annotations-2.5.4.jar
      | | | | | | |____module.xml
      | | | | |____jackson-core
      | | | | | |____4.3.11.Final
      | | | | | | |____jackson-core-2.5.4.jar
      | | | | | | |____module.xml
      | | | | |____jackson-databind
      | | | | | |____4.3.11.Final
      | | | | | | |____jackson-databind-2.5.4.jar
      | | | | | | |____module.xml
      | | | |____jaxrs
      | | | | |____jackson-jaxrs-json-provider
      | | | | | |____4.3.11.Final
      | | | | | | |____jackson-jaxrs-base-2.5.4.jar
      | | | | | | |____jackson-jaxrs-json-provider-2.5.4.jar
      | | | | | | |____jackson-module-jaxb-annotations-2.5.4.jar
      | | | | | | |____module.xml
      |____javax
      | |____annotation
      | | |____api
      | | | |____4.3.11.Final
      | | | | |____jboss-annotations-api_1.2_spec-1.0.0.Final.jar
      | | | | |____module.xml
      | |____api
      | | |____4.3.11.Final
      | | | |____module.xml
      | |____enterprise
      | | |____api
      | | | |____4.3.11.Final
      | | | | |____cdi-api-1.2.jar
      | | | | |____module.xml
      | |____persistence
      | | |____api
      | | | |____4.3.11.Final
      | | | | |____hibernate-jpa-2.1-api-1.0.0.Final.jar
      | | | | |____jbosgi-xservice.properties
      | | | | |____module.xml
      | |____sql
      | | |____api
      | | | |____4.3.11.Final
      | | | | |____jboss-javax-sql-api_7.0_spec-2.0.0.Final.jar
      | | | | |____module.xml
      | |____transaction
      | | |____api
      | | | |____4.3.11.Final
      | | | | |____jboss-transaction-api_1.2_spec-1.0.0.Final.jar
      | | | | |____module.xml
      | |____validation
      | | |____api
      | | | |____4.3.11.Final
      | | | | |____module.xml
      | | | | |____validation-api-1.1.0.Final.jar
      |____modules-tree-dir.txt
      |____org
      | |____hibernate
      | | |____4.3
      | | | |____module.xml
      | | |____4.3.11.Final
      | | | |____hibernate-core-4.3.11.Final.jar
      | | | |____module.xml
      | | |____commons-annotations
      | | | |____4.3.11.Final
      | | | | |____hibernate-commons-annotations-4.0.5.Final.jar
      | | | | |____module.xml
      | | |____entitymanager
      | | | |____4.3.11.Final
      | | | | |____hibernate-entitymanager-4.3.11.Final.jar
      | | | | |____module.xml
      | | |____envers
      | | | |____4.3.11.Final
      | | | | |____hibernate-envers-4.3.11.Final.jar
      | | | | |____module.xml
      | | |____jipijapa-hibernate4_3
      | | | |____4.3
      | | | | |____module.xml
      | | | |____4.3.11.Final
      | | | | |____jipijapa-hibernate4-3-1.0.1.Final.jar
      | | | | |____module.xml
      


      /Flemming.

        • 1. Re: Problem with Wildfly 8.2 and JPA 2.1
          smarlow

          custom Hibernate modules containing the relevant API’s for JPA2.1 and jar files.

          During application deployment, the JPA container calls the PersistenceProvider with parameters passed in from the WildFly copy of the the JPA API classes.  If your custom module also include their own copy of the JPA API's, that is a conflict that causes ClassCastExceptions on the JPA api.  From your description, it sounds more like you are hitting a conflict between different versions of the Hibernate classes.  I don't think this will work as your expecting the application server versions to not be used but they will be, which conflicts with the newer version of jars when the application server call backs into Hibernate occur. 

          • 2. Re: Problem with Wildfly 8.2 and JPA 2.1
            fharms

            I'm unsure if I read you answer correct.


            Are you saying it not possible to setup Wildfly so it use the custom version, instead of the application server version?

            • 3. Re: Problem with Wildfly 8.2 and JPA 2.1
              smarlow

              You can use a custom Hibernate module but you can't include copies of the JPA API jars, as the application server copy of those jars must be used.  The same for the transaction + other standard API jars that conflict with the ones used by WildFly.

               

              Are there JPA 2.1 features that you want to use or more that you just want to use the latest Hibernate ORM version?

              • 4. Re: Problem with Wildfly 8.2 and JPA 2.1
                fharms

                it make sense, but I was hoping I could set it up so I could use JPA 2.1 features?

                • 5. Re: Problem with Wildfly 8.2 and JPA 2.1
                  sannegrinovero

                  Hi Flemming, you should be able to upgrade the Hibernate implementations but a switch of those Java API modules would have a chain effect of essentially upgrading all of the application server .. that's probably not feasible.

                   

                  Why don't you use the JPA 2.1 API modules from WildFly 8.2 ? The spec didn't change from 8 to 10.

                  • 6. Re: Problem with Wildfly 8.2 and JPA 2.1
                    smarlow

                    Sanne is right, Hibernate ORM 4.3.7 is already included in WildFly 8.2 (see release notes here.)

                     

                    Instructions for replacing ORM 4.3.7 with a newer 4.3.x version are here.

                    • 7. Re: Problem with Wildfly 8.2 and JPA 2.1
                      fharms

                      Hi Sanne

                       

                      It's a good question, but I got the idea that WildFly 8 was not compliant with JPA 2.1 because of the paragraph in doc JPA Reference Guide - WildFly 8 - Project Documentation Editor

                      and top of this I unfortunately have looked in the JAR version from EAP 6 because I'm working with both versions at the moment

                      The WildFly 8 JPA subsystem implements the JPA 2.0 container-managed requirements. Deploys the persistence unit definitions, the persistence unit/context annotations and persistence unit/context references in the deployment descriptor. JPA Applications use the Hibernate (core) 4.0 persistence provider, that is included with WildFly. The JPA subsystem uses the standard SPI (javax.persistence.spi.PersistenceProvider) to access the Hibernate persistence provider and some additional extensions as well.

                      • 8. Re: Problem with Wildfly 8.2 and JPA 2.1
                        sannegrinovero

                        Hi Scott,

                        I've updated the WildFly 8 and 9 wiki to mention the right JPA spec version in the opening paragraph, also updated links to Hibernate documentation pages so ported that change to the WildFly 10 wiki too. Could you make sure these get ported to WildFly 11 and beyond? I'm not sure if I had to update some "master" wiki, or if updating the version 10 now would be enough for that.

                         

                        I didn't check details of the content of further down paragraphs as I don't really know all the history there

                         

                        Thanks

                        • 9. Re: Problem with Wildfly 8.2 and JPA 2.1
                          sannegrinovero

                          Ah, I understand your issues better now. Unfortunately EAP6 is based on an older spec, it's quite different than WildFly 8.2 from this point of view.

                           

                          So your question really is more about how to patch an EAP6 instance to run a JPA 2.1 Hibernate?

                           

                          You might be able to replace the JPA 2.0 API jar with the 2.1 API jar, as it's supposedly strictly backwards compatible. Never tried this though..

                          • 10. Re: Problem with Wildfly 8.2 and JPA 2.1
                            fharms

                            Yeah my first step was to solve it for the community version for Wildfly 8, which really was not a problem.... but I confused myself with the EAP version


                            It's an interesting idea with replacing the JPA 2.0 API's. I give it a try see how far I get with the EAP 6 version.

                             

                            Thanks!

                            • 11. Re: Problem with Wildfly 8.2 and JPA 2.1
                              ctomc

                              Flemming Harms wrote:


                              It's an interesting idea with replacing the JPA 2.0 API's. I give it a try see how far I get with the EAP 6 version.

                               

                              Hey Flemming, why don't you give EAP7 a try? it is based of WildFly 10, this way it would be easier for you.

                              or is company policy preventing you to do so?

                               

                              Just keep in mind that "franken EAP6" with jpa2.1 if you make it work, wouldn't be really supported solution by RH, so maybe EAP7 would be much better fit.

                              • 12. Re: Problem with Wildfly 8.2 and JPA 2.1
                                smarlow

                                Excellent, thanks Sanne!

                                • 13. Re: Problem with Wildfly 8.2 and JPA 2.1
                                  smarlow

                                  Regarding WildFly 11 documentation.  In the past, we cloned the https://docs.jboss.org/author/display/WFLYLATEST into the newer WildFly version and went from there.  We might try something different this time as per the discussion on wildfly-dev mailing list.

                                  • 14. Re: Problem with Wildfly 8.2 and JPA 2.1
                                    fharms

                                    Hey Tomaz

                                     

                                    In this case in because of policy and they "expect" to upgrade later this year.


                                    The short story is we have another project using EAP 7 and more specific JPA 2.1, and we want to share some of it work with the other project on EAP 6 until it's upgraded to EAP 7.