5 Replies Latest reply on Sep 26, 2013 10:06 AM by Juliano Carlos da Silva

    JBoss 7.1.1 - How to create a new Hibernate 4 module and exclude the default one ?

    sbourguiba Newbie

      Hi,

       

      I would like to migrate to Hibernate 4.2 version without replacing the existing jars version (4.1.3),

       

      So i tried to create a new module (org.hibernate4) that contain the newer version and refering it in jboss-deployment-structure.xml:

       

      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">

          <ear-subdeployments-isolated>false</ear-subdeployments-isolated>

          <deployment>

              <exclusions>

                  <module name="org.apache.log4j" />

                  <module name="org.hibernate" />

              </exclusions>

              <dependencies>

                  <module name="org.apache.ant" />

                  <module name="org.apache.xalan" />

                  <module name="org.apache.xerces" />

                  <module name="org.slf4j" />

                  <module name="org.jboss.logging" />

                  <module name="org.hibernate4" />

              </dependencies>

          </deployment>

          <sub-deployment name="MyWAR.war">

              <exclusions>

                  <module name="org.apache.log4j" />

                  <module name="org.hibernate" />

              </exclusions>

              <dependencies>

                  <module name="org.apache.ant" />

                  <module name="org.apache.xalan" />

                  <module name="org.apache.xerces" />

                  <module name="org.slf4j" />

                  <module name="org.jboss.logging" />

                  <module name="org.hibernate4" />

              </dependencies>

          </sub-deployment>

          <sub-deployment name="MyEJB.jar">

              <exclusions>

                  <module name="org.apache.log4j" />

                  <module name="org.hibernate" />

              </exclusions>

              <dependencies>

                  <module name="org.apache.ant" />

                  <module name="org.apache.xalan" />

                  <module name="org.apache.xerces" />

                  <module name="org.slf4j" />

                  <module name="org.jboss.logging" />

                  <module name="org.hibernate4" />

              </dependencies>

          </sub-deployment>

      </jboss-deployment-structure>

       

      But when starting the server the version 4.1.3 is loaded (20:41:54,239 INFO  [org.hibernate.Version] (MSC service thread 1-1) HHH000412: Hibernate Core {4.1.3.Final-redhat-1}) and i got this exception:

       

      Caused by: java.lang.ClassCastException: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider cannot be cast to org.hibernate.service.jdbc.connections.spi.ConnectionProvider

          at org.hibernate.service.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:189)

          ... 26 more

       

      How can i exclude the default hibernate 4 module and using a new one ?

       

      I have to add a provider module in my persistence.xml ?

       

      Thanks in advance.

        • 1. Re: JBoss 7.1.1 - How to create a new Hibernate 4 module and exclude the default one ?
          Scott Marlow Master

          This is reported as a bug via https://issues.jboss.org/browse/WFLY-1151, try again with WildFly 8 Alpha2.

           

          and copy the Hibernate 4.2 jars into the modules/system/layers/base/org/hibernate/4.1 folder (works with Hibernate 4.1.x + 4.2.x).  Update module.xml to include the Hibernate jar names.  You can look at an example of specifying the Hibernate jar names in modules/system/layers/base/org/hibernate/main which specifies the Hibernate 4.3.x jars in WF8.

           

          To specify a different persistence unit module, set persistence unit hint:

             <property name="jboss.as.jpa.providerModule" value="org.hibernate:4.1"/>

           

          In your case, since the Hibernate 4.3 persistence provider class name changed (new name is org.hibernate.jpa.HibernatePersistenceProvider), you just need to reference the org.hibernate.ejb.HibernatePersistence provider in your persistence.xml and the "org.hibernate:4.1" module will be used.

           

          Scott

          • 2. Re: JBoss 7.1.1 - How to create a new Hibernate 4 module and exclude the default one ?
            sbourguiba Newbie

            Ok Scott, thanks for your reply

             

            I tried to find a workaround in order to use Jboss 7.1.1 and Hibernate 4.2, so i have added Hibernate 4.2 jars in my Ear and those tags in persistence.xml:

             

            <property name="jboss.as.jpa.providerModule" value="application"/>

            <property name="hibernate.ejb.resource_scanner" value="org.hibernate.ejb.packaging.NativeScanner"/>

            <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/>

             

            When i start the server the version 4.2 of Hibernate is loaded successfully ([org.hibernate.Version] (MSC service thread 1-4) HHH000412: Hibernate Core {4.2.0.Final}), but I got this exception:

             

            12:04:18,502 INFO  [org.jboss.web] (MSC service thread 1-2) JBAS018210: Enregistrement du contexte web /testApplication

            12:04:18,518 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014612: L'opÚration ("add") a ÚchouÚ - adresse : ([("subsystem" => "logging")]): java.lang.ClassCastException: org.hibernate.ejb.EntityManagerFactoryImpl cannot be cast to org.hibernate.ejb.HibernateEntityManagerFactory

                    at org.jboss.as.jpa.hibernate4.management.ManagementLookup.create(ManagementLookup.java:55)

                    at org.jboss.as.jpa.hibernate4.management.HibernateStatisticsResource.getStatistics(HibernateStatisticsResource.java:389)

                    at org.jboss.as.jpa.hibernate4.management.HibernateStatisticsResource.getEntityNames(HibernateStatisticsResource.java:277)

                    at org.jboss.as.jpa.hibernate4.management.HibernateStatisticsResource.getChildren(HibernateStatisticsResource.java:206)

                    at org.jboss.as.controller.registry.AbstractModelResource$DelegateResource.getChildren(AbstractModelResource.java:255) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:245) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:232) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:219) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:247) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:232) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:219) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:247) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:232) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:219) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:247) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:232) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:219) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:247) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:232) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:219) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.registry.Resource$Tools.readModel(Resource.java:208) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.ModelControllerImpl.writeModel(ModelControllerImpl.java:394) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.OperationContextImpl.createPersistenceResource(OperationContextImpl.java:163) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.AbstractOperationContext.doCompleteStep(AbstractOperationContext.java:319) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.AbstractOperationContext.completeStep(AbstractOperationContext.java:211) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.AbstractOperationContext.finishStep(AbstractOperationContext.java:463) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:450) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.AbstractOperationContext.doCompleteStep(AbstractOperationContext.java:284) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.AbstractOperationContext.completeStep(AbstractOperationContext.java:211) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.server.AbstractDeploymentChainStep.execute(AbstractDeploymentChainStep.java:51)

                    at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:397) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.AbstractOperationContext.doCompleteStep(AbstractOperationContext.java:284) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.AbstractOperationContext.completeStep(AbstractOperationContext.java:211) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.ParallelBootOperationStepHandler$1.execute(ParallelBootOperationStepHandler.java:262) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:397) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.AbstractOperationContext.doCompleteStep(AbstractOperationContext.java:284) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.AbstractOperationContext.completeStep(AbstractOperationContext.java:211) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.ParallelBootOperationStepHandler.execute(ParallelBootOperationStepHandler.java:161) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:397) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.AbstractOperationContext.doCompleteStep(AbstractOperationContext.java:284) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.AbstractOperationContext.completeStep(AbstractOperationContext.java:211) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.ModelControllerImpl.boot(ModelControllerImpl.java:175) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.controller.AbstractControllerService.boot(AbstractControllerService.java:191) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at org.jboss.as.server.ServerService.boot(ServerService.java:295)

                    at org.jboss.as.server.ServerService.boot(ServerService.java:270)

                    at org.jboss.as.controller.AbstractControllerService$1.run(AbstractControllerService.java:156) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]

                    at java.lang.Thread.run(Thread.java:619) [rt.jar:1.6.0_21]

             

            you have an idea about the cause of this exception ?

            • 5. Re: JBoss 7.1.1 - How to create a new Hibernate 4 module and exclude the default one ?
              Juliano Carlos da Silva Newbie

              I am testing with a WAR package.

              Using maven, add hibernate 4.2.5 in pom then its going to WEB-INF/lib

              add to jboss-deployment-structure.xml

              <module name="org.hibernate" />

              <module name="org.hibernate.commons-annotations" />

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

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

               

              in persitence.xml

              <property name="hibernate.ejb.resource_scanner" value="org.hibernate.ejb.packaging.NativeScanner"/>

               

              and try with {

              <property name="jboss.as.jpa.providerModule" value="application"/>

              <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/>

              }

               

              but no sucess yet