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.
My problem has arisen from my attempts to deploy a second MBean to reference a separate database. The first approach I used was to simply deploy a second MBean SAR, after changing the requisite JNDI name. The MBeans deployed correctly and the SessionOBjectFactories were bound to the proper JNDI locations. Subsequently all attempts to reference any of the existing tables in the second MBean(as in the MBean that loaded second) resulted in the error message that "No persistent classes found for ...". I surmised that this might be due to the vagaries of the JBoss UnifiedClassloader, so I added the classloader tag <loader-repository> ... to the jboss-service.xml. This was no help and neither were my other attempts to package the MBean in a more self contained manner. I tried to place the MBean SAR inside of a separate EAR to provide further classloader containment, but to no avail.
I also 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 question is how are folks handling deployment of mulitple hibernate MBeans. In my particular case, I have many webapps and only 2 separate databases. Is it possible to deploy only the expected minimum 2 MBeans to service all of my webapps? This would seem to be the logical approach and perhaps I've just missed something in my implementation.
-
Hibernate version:2.1
Mapping documents: for first MBean
<server>
<loader-repository>hibernate.ols:loader=hibernate-ols.sar</loader-repository>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactory,
name=HibernateFactory">
<depends>jboss.jca:service=RARDeployer</depends>
<depends>jboss.jca:service=LocalTxCM,name=olsDB</depends>
<!-- Make it deploy ONLY after DataSource had been started -->
<attribute name="MapResources">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</attribute>
<attribute name="JndiName">java:/HibernateFactory</attribute>
<attribute name="Datasource">java:/olsDB</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.MySQLDialect</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name="UseOuterJoin">false</attribute>
<attribute name="ShowSql">false</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
<attribute name="CacheProvider">net.sf.ehcache.hibernate.Provider</attribute>
<attribute name="UseQueryCache">true</attribute>
</mbean>
</server>
Mapping documents: for second MBean:
<server>
<loader-repository>hibernate.ols.email:loader=hibernate-ols-email.sar</loader-repository>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=HibernateFactoryEmail,
name=HibernateFactoryEmail">
<depends>jboss.jca:service=RARDeployer</depends>
<depends>jboss.jca:service=LocalTxCM,name=olsDBemail</depends>
<!-- Make it deploy ONLY after DataSource had been started -->
<attribute name="MapResources">map/EmailMessage.hbm.xml,map/ForwardBounce.hbm.xml,
map/SenderAccount.hbm.xml</attribute>
<attribute name="JndiName">java:/HibernateFactoryEmail</attribute>
<attribute name="Datasource">java:/olsDBemail</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.MySQLDialect</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name="UseOuterJoin">false</attribute>
<attribute name="ShowSql">false</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
<attribute name="CacheProvider">net.sf.ehcache.hibernate.Provider</attribute>
<attribute name="UseQueryCache">true</attribute>
</mbean>
</server>
Name and version of the database you are using:Mysql 4.0.18
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt: