4 Replies Latest reply on Jun 27, 2012 3:20 PM by madchedar0

    Migrating Hibernate 3.x dependent code from JBoss 5.1.0GA to JBoss 7.1.1

    madchedar0 Newbie

      As suggested by Wolf-Dieter in this thread https://community.jboss.org/message/740234#740234 I'm posting my question here.

       

      I have services which I'm migrating from the JBoss 5.1.0GA ecosystem to JBoss 7.1.1

       

      Some of the more "complex" services depend on Hibernate in order to function.  It seems that some of the Hibernate 3.x classes don't exist in Hibernate 4.x? (JBoss 7.1.1 ships with 4.1 I believe).

      Does Hibernate 4.1 have support for org.hibernate.criterion.* like Hibernate 3.x did?

       

       

      Here's what my services generally look like:

       

       

       

      import org.hibernate.Session;
      import org.hibernate.criterion.Order;
      import org.hibernate.criterion.Restrictions;
      import javax.ejb.Startup;
      import javax.ejb.Singleton;
      
      @Singleton 
      @Startup
      public class SomeServiceManager implements Serializable, SomeServiceManagerMBean {
      
      // ... methods that use org.hibernate.criterion classes...
      
      }
      

       

      Unless I include hibernate3.jar (from Hibernate 3.x) in my application's .ear (nexus.ear), I get the following error :

       

      13:41:25,378 INFO  [org.jboss.weld.deployer] (MSC service thread 1-8) JBAS016008: Starting weld service for deployment nexus.ear

      13:41:25,386 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-15) MSC00001: Failed to start service jboss.deployment.subunit."nexus.ear"."nexus.sar".INSTALL: org.jboss.msc.service.StartExcepti

      on in service jboss.deployment.subunit."nexus.ear"."nexus.sar".INSTALL: Failed to process phase INSTALL of subdeployment "nexus.sar" of deployment "nexus.ear"

              at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:119) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

              at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]

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

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

              at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_30]

      Caused by: java.lang.RuntimeException: Error getting reflective information for class com.SomeServiceManager with ClassLoader ModuleClassLoader for Module "deployment.nexus.ear:main" f

      rom Service Module Loader

              at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:70) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.as.service.ReflectionUtils.getClassHierarchy(ReflectionUtils.java:124)

              at org.jboss.as.service.ParsedServiceDeploymentProcessor.addServices(ParsedServiceDeploymentProcessor.java:108)

              at org.jboss.as.service.ParsedServiceDeploymentProcessor.deploy(ParsedServiceDeploymentProcessor.java:99)

              at org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:113) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

              ... 5 more

      Caused by: java.lang.NoClassDefFoundError: org/hibernate/criterion/Criterion

              at java.lang.Class.getDeclaredFields0(Native Method) [rt.jar:1.6.0_30]

              at java.lang.Class.privateGetDeclaredFields(Class.java:2291) [rt.jar:1.6.0_30]

              at java.lang.Class.getDeclaredFields(Class.java:1743) [rt.jar:1.6.0_30]

              at org.jboss.as.server.deployment.reflect.ClassReflectionIndex.<init>(ClassReflectionIndex.java:57) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

              at org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex.getClassIndex(DeploymentReflectionIndex.java:66) [jboss-as-server-7.1.1.Final.jar:7.1.1.Final]

              ... 9 more

      Caused by: java.lang.ClassNotFoundException: org.hibernate.criterion.Criterion from [Module "deployment.nexus.ear:main" from Service Module Loader]

              at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:190) [jboss-modules.jar:1.1.1.GA]

              at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:468) [jboss-modules.jar:1.1.1.GA]

              at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:456) [jboss-modules.jar:1.1.1.GA]

              at org.jboss.modules.ConcurrentClassLoader.performLoadClassChecked(ConcurrentClassLoader.java:423) [jboss-modules.jar:1.1.1.GA]

              at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398) [jboss-modules.jar:1.1.1.GA]

              at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:120) [jboss-modules.jar:1.1.1.GA]

              ... 14 more

       

       

      Besides including hibernate3.jar in my .ear to avoid this error... is there a better way?  What's the right way to do this in JBoss 7.1.1?  Are there equivalent classes for criterion.Order and criterion.Restrictions in Hibernate 4.1?

       

      Thanks

        • 1. Re: Migrating Hibernate 3.x dependent code from JBoss 5.1.0GA to JBoss 7.1.1
          Tomaz Cerar Master

          Hi,

           

          hibernate 4 also has this classes so it should not be problem.

          Did you try to recompiling/rebuilding your application with hibernate 4.1 instead of hibernate 3?

           

          there ware some package name changes but not much more that this.

           

          also did you include module "org.hibernate" as dependancy in MANIFEST.mf / jboss-deployment-structure.xml?

           

          --

          tomaz

          • 2. Re: Migrating Hibernate 3.x dependent code from JBoss 5.1.0GA to JBoss 7.1.1
            madchedar0 Newbie

            Thanks Tomaz!

             

            I forgot to include org.hibernate in my jboss-deployment-structure.xml so now it looks something like this (for anyone wondering):

             

            <jboss-deployment-structure>

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

                <deployment>

                    <dependencies>

                        <module name="org.hibernate"/>

                    </dependencies>

                </deployment>

            </jboss-deployment-structure>

             

            I think I'm building with Hibernate 4.1... at least now I'm not including the hibernate3.jar in the .ear!  I take it now since "org.hibernate" has been specified as a dependency that jboss7.1.1 is using Hibernate 4.1.  I'll have to go through later and make sure the old hibernate3.jar (and related jars) are not being used and instead use hibernate-core-4.0.1.Final.jar (and those similar, newer jars)

             

            Thanks again!

            • 3. Re: Migrating Hibernate 3.x dependent code from JBoss 5.1.0GA to JBoss 7.1.1
              jaikiran pai Master

              Just curious - You don't use JPA in your application but use hibernate directly? If you had JPA (the persistence.xml minimally) then that would have triggered AS7 to automatically add a dependency on org.hibernate module for your application at runtime. It's fine if you aren't using JPA, in which case you can add that dependency manually, like you just did.

              • 4. Re: Migrating Hibernate 3.x dependent code from JBoss 5.1.0GA to JBoss 7.1.1
                madchedar0 Newbie

                jaikiran pai wrote:

                 

                Just curious - You don't use JPA in your application but use hibernate directly? If you had JPA (the persistence.xml minimally) then that would have triggered AS7 to automatically add a dependency on org.hibernate module for your application at runtime. It's fine if you aren't using JPA, in which case you can add that dependency manually, like you just did.

                 

                The application I'm migrating uses hibernate directly - this worked fine in JBoss 5.1.0GA... we never upgraded to JPA.  Currently we have a har that we're deploying.  But from what I read har deployments are not supported in JBoss 7.1.1. 

                 

                I guess I was hoping I could at least get some of my services in my sar deployed (that used hibernate) but not actually have them been useable.  ("Useable" meaning I could have hibernate access my DB and extract data.  I just wanted to know hibernate was running on my application server.)

                 

                I guess I didn't realize until yesterday that .har isn't supported in JBoss 7.x.... so now I'm looking into JPA and what it might take to integrate that in our code.

                 

                As a side note:

                 

                After I included the org.hibernate dependency and resolved the java.lang.ClassNotFoundException, I started getting

                "

                JBAS014775:New missing/unsatisfied dependencies"

                "

                relating to my hibernate session factory.  So I'm guessing JPA integration is probably the way to go.  I'll report back/or make a new thread when I find out the answer.

                 

                Edit: I ended up creating a @Singleton bean which on @Startup programmatically loads all the .hbm.xml files in our system and that bean therefore can create the Hibernate SessionFactory which is used to access the database.  Hopefully that helps someone.