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();
ClassLoader cl = Thread.currentThread().getContextClassLoader(); Class cfgClass = cl.findClass("org.hibernate.cfg.Configuration"); Configuration cfg = cfgClass.newInstance();