1 2 Previous Next 24 Replies Latest reply: Aug 18, 2008 8:37 AM by Justin G RSS

Upgrading hibernate in JBoss 4.2.2.GA

Justin G Newbie

Hi,

I have an application that requires an upgrade to the version of hibernate that is bundled with JBoss 4.2.2.GA. If I bundle the new hibernate jars in my application ear, will my application be guaranteed to use the upgraded version as opposed to the version bundled in server//lib/? Or, do I need to replace the jars in server//lib/? I'd like to keep them in my application ear if possible, but I'm not positive on how the classpath is setup.

Thanks.

justin.

  • 1. Re: Upgrading hibernate in JBoss 4.2.2.GA
    Justin G Newbie

    Argh, forum didn't like the formatting in my original post. The path I meant to type is: /server/< config >/lib/

  • 2. Re: Upgrading hibernate in JBoss 4.2.2.GA
    jaikiran pai Master

    You can package your own version of Hibernate within your application without having to replace the ones in server/< serverName>/lib folder. You will have to setup classloader scoping for your application. Read through these:

    http://wiki.jboss.org/wiki/JBossClassLoadingUseCases

    http://wiki.jboss.org/wiki/ClassLoadingConfiguration

  • 3. Re: Upgrading hibernate in JBoss 4.2.2.GA
    Justin G Newbie

    thanks!

  • 4. Re: Upgrading hibernate in JBoss 4.2.2.GA
    Justin G Newbie

    OK, I can't seem to get this working. I'm clearly doing something wrong. Essentially, I want my ear application to use hibernate v3.2.6. Here is the structure of my ear (containing the upgraded hibernate):

    myEar
    |-- META-INF
    | |-- application.xml
    | |-- jboss-app.xml
    | `-- MANIFEST.MF
    |-- lib
    | |-- hibernate-annotations.jar
    | |-- hibernate-commonds-annotations.jar
    | |-- hibernate-entitymanager.jar
    | `-- hibernate3.jar
    |-- myEjb.jar
    `-- myWar.war
    

    My jboss-app.xml looks like this (does the contents of "org.myOrg" or "myEarLoader" make a difference here?):
    <jboss-app>
     <loader-repository>
     org.myOrg:archive=myEarLoader
     <loader-repository-config>
     java2ParentDelegation=false
     </loader-repository-config>
     </loader-repository>
    </jboss-app>
    

    The MANIFEST.MF of my myEjb.jar includes all the hibernate jars in the Class-path:
    Manifest-Version: 1.0
    Class-Path: lib/hibernate-annotations.jar
     lib/hibernate-commons-annotations.jar
     lib/hibernate-entitymanager.jar
     lib/hibernate3.jar
    

    The ejb just starts a jboss service bean and prints out the current hibernate version. No matter how much tinkering I do, I always see this:
    [STDOUT] Hibernate Version: 3.2.4.sp1
    [STDOUT] Hibernate Annotations Version: 3.2.1.GA
    [STDOUT] Hibernate EM Version: 3.2.1.GA
    

    What am I missing?

    thanks.

    justin.

  • 5. Re: Upgrading hibernate in JBoss 4.2.2.GA
    jaikiran pai Master

     

    "jinpsu" wrote:

    My jboss-app.xml looks like this (does the contents of "org.myOrg" or "myEarLoader" make a difference here?)


    The names don't make a difference as long as they are unique.


    "jinpsu" wrote:

    The MANIFEST.MF of my myEjb.jar includes all the hibernate jars in the Class-path:
    Manifest-Version: 1.0
    Class-Path: lib/hibernate-annotations.jar
     lib/hibernate-commons-annotations.jar
     lib/hibernate-entitymanager.jar
     lib/hibernate3.jar
    



    Can you remove that Classpath entry from the Manifest of the ejb and try. I don't think that's going to make a difference, but lets remove that possibility.

    "jinpsu" wrote:

    The ejb just starts a jboss service bean and prints out the current hibernate version. No matter how much tinkering I do, I always see this:
    [STDOUT] Hibernate Version: 3.2.4.sp1
    [STDOUT] Hibernate Annotations Version: 3.2.1.GA
    [STDOUT] Hibernate EM Version: 3.2.1.GA
    



    Can you post the entire console logs (from the time when you start JBoss)?

  • 6. Re: Upgrading hibernate in JBoss 4.2.2.GA
    Justin G Newbie

    Well I tried to do you one better and create a simple project that illustrates the problem. I created two projects in eclipse (myEjb and myEar), built and deployed them. As expected, the service bean printed out the old hibernate versions. I then wrote an ant script to build the same projects. I deployed that and all of a sudden the service bean prints out the updated hibernate versions!?

    I don't get it. I extracted both ears and compared every file, the only differences were the two .class files (one built by eclipse, one by ant). Just to make sure I wasn't nuts, I updated the working (ant) ear with the two .class files from the broken (eclipse) ear. It then printed the old hibernate versions.

    Eclipse (3.4) and ant (1.7.0) are both configured to use jdk5 (1.5.0_16), jboss is also using java5. What am I missing?

    thanks!

    justin.

  • 7. Re: Upgrading hibernate in JBoss 4.2.2.GA
    jaikiran pai Master

    What code is present in those class files? Can you post it?

  • 8. Re: Upgrading hibernate in JBoss 4.2.2.GA
    Justin G Newbie

    Sure.

    MyManagedIfc.java

    package org.myOrg;
    
    import org.jboss.annotation.ejb.Management;
    
    @Management
    public interface MyManagedIfc {
     void create() throws Exception;
     void start() throws Exception;
     void stop();
     void destroy();
    }
    


    MyManagedBean.java
    package org.myOrg;
    
    import org.jboss.annotation.ejb.Service;
    import org.jboss.annotation.ejb.Management;
    
    @Service
    @Management(org.myOrg.MyManagedIfc.class)
    public class MyManagedBean implements MyManagedIfc {
    
     public MyManagedBean() {
     System.out.println("MyManagedBean()\n");
     }
    
     public void create() throws Exception {
     System.out.println("MyManagedBean.create()\n");
     }
    
     public void start() throws Exception {
     System.out.println("MyManagedBean.start()\n");
    
     System.out.println(" \n");
     System.out.println("Hibernate Version: " + org.hibernate.cfg.Environment.VERSION);
     System.out.println("Hibernate Annotations Version: " + org.hibernate.cfg.annotations.Version.VERSION);
     System.out.println("Hibernate EM Version: " + org.hibernate.ejb.Version.VERSION);
     System.out.println(" \n");
     }
    
     public void stop() {
     System.out.println("MyManagedBean.stop()\n");
     }
    
     public void destroy() {
     System.out.println("MyManagedBean.destroy()\n");
     }
    }
    


  • 9. Re: Upgrading hibernate in JBoss 4.2.2.GA
    Justin G Newbie

    After disassembling the bean class file I noticed that the static version strings were listed as the old hibernate version. So this turned out to just be a build path issue in eclipse that kicked by butt.

    Thanks for looking into it, jaikiran!

    justin.

  • 10. Re: Upgrading hibernate in JBoss 4.2.2.GA
    Justin G Newbie

    Well, this still isn't working correctly. My .war file within the .ear is still trying to use the old hibernate version in the jboss lib directory. I see this exception when the .war tries to use hibernate:

    Caused by: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.Class,
    java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map,
    org.hibernate.annotations.common.reflection.ReflectionManager)
     at java.lang.Class.getConstructor0(Class.java:2678)
     at java.lang.Class.getDeclaredConstructor(Class.java:1953)
     at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:357)
     ... 67 more
    

    The ClassValidator class is in the bundled jboss hibernate jars, not the jars in my .ear.

    Not sure if this matter or not, but I'm using oracle and my jdbc driver (ojdbc14.jar) is in server/< config >/lib/. My oracle-ds.xml is in the root of my ear.

    How can I debug this further?

    thanks.

    justin.

  • 11. Re: Upgrading hibernate in JBoss 4.2.2.GA
    jaikiran pai Master

    Are you sure you have packaged the correct versions of all appropriate hibernate jars in your application? See the Compatibility Matrix for more details http://www.hibernate.org/6.html#A3.

    Please post the exact versions of various hibernate jars that you have packaged in your application

  • 12. Re: Upgrading hibernate in JBoss 4.2.2.GA
    Justin G Newbie

    The hibernate jars in my ear are:
    Hibernate Core 3.2.6.GA
    Hibernate Annotations 3.3.1.GA
    Hibernate EntityManager 3.3.2.GA

    These all work fine together. If I copy the jars in my ear (hibernate3.jar, hibernate-annotations.jar, hibernate-commons-annotations.jar, hibernate-entitymanager.jar) into jboss-4.2.2.GA/server/default/lib/ everything works great.

    justin.

  • 13. Re: Upgrading hibernate in JBoss 4.2.2.GA
    Justin G Newbie

    Are there any configuration files I'm missing? Or am I going about this the wrong way? Again, everything works fine if I just overwrite the hibernate jars in the jboss server lib directory. However, if I keep the original hibernate jars in the jboss server lib directory, copy the new jars into the lib directory of my ear, and specify the loader-repository in jboss-app.xml, it breaks.

    Should I be packaging hibernate differently in my ear? Put it in a .sar or .har? I'm grasping at straws at this point.

    justin.

  • 14. Re: Upgrading hibernate in JBoss 4.2.2.GA
    jaikiran pai Master

     

    Or am I going about this the wrong way? Should I be packaging hibernate differently in my ear? Put it in a .sar or .har?


    What you have done so far (using the classloader scoping) is the correct way.

    Caused by: java.lang.NoSuchMethodException: org.hibernate.validator.ClassValidator.<init>(java.lang.Class,
    java.util.ResourceBundle, org.hibernate.validator.MessageInterpolator, java.util.Map,
    org.hibernate.annotations.common.reflection.ReflectionManager)


    The exception that you are getting, does indicate that the classloader scoping is working and "your" hibernate jars have been picked up. If they weren't picked up, then you wouldn't have seen any exceptions since JBoss already has all the required correct versions of the jars.

    All we have to do now is figure out that your application has packaged all the "required" hibernate jars and the correct version of each of them. Let me try and find the thread where we had a similar discussion about upgrading hibernate in JBoss.

    By the way, i believe your WAR does not have any hibernate related jars. All those hibernate jars are in the lib of the EAR right? And what version is the hibernate-commons-annotations.jar? (You can open the MANIFEST.MF in that jar and see the version details).



1 2 Previous Next