2 Replies Latest reply on Sep 23, 2004 1:22 PM by Jeff Doran

    Multiple Hibernate MBean deployment in JBoss?

    Jeff Doran Newbie

      I've been using hibernate 2.1 with mysql 4.0.18 inside of JBoss 3.2.3 for sometime with good results. I have the hibernate files (mapping and bean files) deployed as an MBean in a separate Service Archive (SAR) as described on the Hibernate web site(www.hibernate.org/66.html). The hibernate library and related jars are deployed in JBOSS_HOME/server/default/lib. This MBean is accessed by several webapps deployed in the same JBoss instance.

      I've run into a problem trying to deploy a second MBean inside a SAR to access a 2nd database. My deployment approaches have included deploying 2 separate SARs, including the SARs in the webapp EARs, and packaging the MBean SARs inside their own separate EARs. All of these approaches have proved problematic.

      The use of multiple SARs loaded fine, bound to JNDI fine, but failed at runtime with Hibernate complaining that "no persistent classes found for..." my beans which were inside the respective SARs. I suspected this was due to classpath loading issues and I tried the <loader-repository> tag in jboss-service.xml, but no luck.

      I next tried to place the MBean SAR inside of each webapp EAR. This worked upto the point where I needed to have multiple copies of the MBean which caused JNDI conflicts. While it's possible that I could create identical copies of the MBeans with slightly different JNDI names for each client webapp to deploy, this seems the wrong way to go.

      My final option of packaging gthe MBean SAR inside its own EAR also deployed and bound to JNDI correctly according to the JMX console and server.log. The problem here is that I can't create a SessionFactoryObject from the JNDI lookup. It performs the lookup without an exception, but the factory is always null. This occurs even when I deploy only a single MBean EAR, so I suspect it's something wrong with my packaging.

      Maybe someone can see a flaw in my approach. I'll include full info for the first MBean since that now has the null session problem when deployed by itself. The second MBean is packaged in a similar manner.



      My first MBean jboss-service.xml:



      <loader-repository>hibernate.ols:loader=hibernate-ols.sar</loader-repository>


      jboss.jca:service=RARDeployer
      jboss.jca:service=LocalTxCM,name=olsDB
      <!-- Make it deploy ONLY after DataSource had been started -->
      map/Company.hbm.xml,map/Language.hbm.xml,map/Manifest.hbm.xml, map/Manifestexcludeservice.hbm.xml,map/Manifestservice.hbm.xml, map/Oem.hbm.xml,map/Product.hbm.xml,map/Service.hbm.xml, map/Servicerank.hbm.xml,map/User.hbm.xml,map/Notification.hbm.xml, map/Servicetracking.hbm.xml,map/Companylanguage.hbm.xml, map/Country.hbm.xml,map/Media.hbm.xml
      java:/HibernateFactory
      java:/olsDB
      net.sf.hibernate.dialect.MySQLDialect
      net.sf.hibernate.transaction.JTATransactionFactory
      net.sf.hibernate.transaction.JBossTransactionManagerLookup
      false
      false
      UserTransaction
      net.sf.ehcache.hibernate.Provider
      true






      My first MBean ear application.xml

      <?xml version="1.0" encoding="UTF-8"?>

      <display-name>OLS Hibernate service </display-name>


      hibernate-ols.sar



      hibernate2.jar



      cglib-2.0-rc2.jar



      commons-logging-1.0.3.jar



      commons-collections-2.1.jar



      dom4j-1.4.jar



      odmg-3.0.jar



      ehcache-0.7.jar





      My first MBean ear jboss-app.xml

      <jboss-app>
      <loader-repository>hibernate.ols.com:loader=hibernate-ols.ear</loader-repository>
      </jboss-app>



      My second MBean jboss-service.xml:



      <loader-repository>hibernate.ols.email:loader=hibernate-ols-email.sar</loader-repository>

      jboss.jca:service=RARDeployer
      jboss.jca:service=LocalTxCM,name=olsDBemail
      <!-- Make it deploy ONLY after DataSource had been started -->
      map/EmailMessage.hbm.xml,map/ForwardBounce.hbm.xml, map/SenderAccount.hbm.xml
      java:/HibernateFactoryEmail
      java:/olsDBemail
      net.sf.hibernate.dialect.MySQLDialect
      net.sf.hibernate.transaction.JTATransactionFactory
      net.sf.hibernate.transaction.JBossTransactionManagerLookup
      false
      false
      UserTransaction
      net.sf.ehcache.hibernate.Provider
      true






        • 1. Re: Multiple Hibernate MBean deployment in JBoss?
          Ivelin Ivanov Expert



          http://www.jboss.org/wiki/Wiki.jsp?page=JBossHibernate

          Not answering your question directly but it might help.

          Ivelin

          • 2. Re: Multiple Hibernate MBean deployment in JBoss?
            Jeff Doran Newbie

            Thanks for the suggestion, but I'd already perused that page. Assuming that you can package an MBean SAR inside an EAR for global access, then I'm just missing some small deployment tweak.

            The latest clue is that I see a successful instantiation and binding of a SessionFactoryObject :


            2004-09-23 10:08:34,330 DEBUG [net.sf.hibernate.impl.SessionFactoryObjectFactory] initializing class SessionFactoryObjectFactory
            2004-09-23 10:08:34,340 DEBUG [net.sf.hibernate.impl.SessionFactoryObjectFactory] registered: 8a8767beff2c43f900ff2c43ff900000 (java:/HibernateFactory)
            2004-09-23 10:08:34,340 INFO [net.sf.hibernate.impl.SessionFactoryObjectFactory] Factory name: java:/HibernateFactory
            2004-09-23 10:08:34,340 INFO [net.sf.hibernate.util.NamingHelper] JNDI InitialContext properties:{}
            2004-09-23 10:08:34,340 DEBUG [net.sf.hibernate.util.NamingHelper] binding: java:/HibernateFactory
            2004-09-23 10:08:34,340 DEBUG [net.sf.hibernate.impl.SessionFactoryImpl] Returning a Reference to the SessionFactory
            2004-09-23 10:08:34,340 DEBUG [net.sf.hibernate.util.NamingHelper] Bound name: java:/HibernateFactory
            2004-09-23 10:08:34,340 INFO [net.sf.hibernate.impl.SessionFactoryObjectFactory] Bound factory to JNDI name: java:/HibernateFactory


            and then a subsequent failure on lookup:

            2004-09-23 10:18:30,517 DEBUG [net.sf.hibernate.impl.SessionFactoryObjectFactory] JNDI lookup: HibernateFactory
            2004-09-23 10:18:30,517 DEBUG [net.sf.hibernate.impl.SessionFactoryObjectFactory] lookup: uid=8a8767beff2c43f900ff2c43ff900000
            2004-09-23 10:18:30,517 WARN [net.sf.hibernate.impl.SessionFactoryObjectFactory] Not found: 8a8767beff2c43f900ff2c43ff900000
            2004-09-23 10:18:30,517 DEBUG [net.sf.hibernate.impl.SessionFactoryObjectFactory] {}