0 Replies Latest reply on Apr 27, 2006 4:24 PM by esword

    Can you isolate newer version of Hibernate in JBoss 4.0.3SP1

    esword Newbie

      I want to use hibernate 3.0.2 in my ear under JBoss 4.0.3SP1 without touching the default install of hibernate in the server/default/lib directory (I need to play nice with any other apps that are expecting that version of hibernate). I also want to use the har service (i.e. the org.jboss.hibernate.jmx.Hibernate MBean). I am using an ear with isolated class loading. The ear contains a .deployer which loads up all the third party jars I use, including the newer hibernate3.jar.

      If I use the HibernateMBean, it will instantiate the org.hibernate.cfg.Configuration using classes from the hibernate3.jar in server/default/lib, thus causing the session factory and everything else to come from there.

      The only solution I have found is to put a copy of jboss-hibernate.jar into the .deployer in my ear. The HibernateMBean is then loaded with my ear's class loader, and the call to

       Configuration cfg = new Configuration();

      in buildSessionFactory() also uses that class loader and properly pulls the newer hibernate classes from the hibernate3.jar local to my app.

      Is there any other way to do this that I am missing? It seems like HibernateMBean should either have an optional ConfigurationFactory attribute which can return a new Configuration object (using the right class loader) or possibly it should do something like:

      ClassLoader cl = Thread.currentThread().getContextClassLoader();
      Class cfgClass = cl.findClass("org.hibernate.cfg.Configuration");
      Configuration cfg = cfgClass.newInstance();

      Pardon me if that wouldn't work. My knowledge of ClassLoaders has grown by about 1000% in the past two days while pounding my head on this, but it is still very limited.