Multiple Hibernate MBean deployment in JBoss?
jeffrow Sep 23, 2004 12:34 PMI'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