Hi. I'm using Hibernate 2.1 with JBoss 3.2.1 and am having a problem trying to use Hibernate as an MBean.
The problem I am having does not occur when I first start up JBoss; rather, it only happens after I rebuild my application and do a hot deploy of my .ear file to JBoss.
After the hot deploy, I get the following warning from Hibernate and my find method returns no rows:
Code:
2004-04-13 23:49:33,646 WARN [net.sf.hibernate.hql.QueryTranslator] no persistent classes found for query class: from com.taos.server.hibernate.jaws.JawsJob
I noticed that when I get a SessionFactory the first time, hibernate logs all of the attributes/mappings it found in the mbean; however, after redeploying my .ear file and rerunning my application, these log statements are not generated. I have to actually restart JBoss to make it work again.
Any ideas would be greatly appreciated.
here is my jboss-service.xml file
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server>
<server>
<mbean code="net.sf.hibernate.jmx.HibernateService" name="jboss.jca:service=Hibernate">
<depends>jboss.jca:service=RARDeployer</depends>
<attribute name="MapResources">com/taos/server/hibernate/jaws/JawsJob.hbm.xml,
com/taos/server/hibernate/jaws/JobEndStartCond.hbm.xml
</attribute>
<attribute name="JndiName">java:/HibernateFactory</attribute>
<attribute name="Datasource">java:jdbc/jaws</attribute>
<attribute name="Dialect">net.sf.hibernate.dialect.SQLServerDialect</attribute>
<attribute name="UseOuterJoin">true</attribute>
<attribute name="ShowSql">true</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
<attribute name="TransactionStrategy">net.sf.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">net.sf.hibernate.transaction.JBossTransactionManagerLookup</attribute>
<attribute name="CacheProvider"> net.sf.ehcache.hibernate.Provider</attribute>
</mbean>
</server>
HibernateUtility.java
Code:
public class HibernateUtility {
private static final SessionFactory jawsSessionFactory;
static {
try {
jawsSessionFactory = setupJawsSessionFactory();
}
catch (TaosException ex) {
throw new RuntimeException("Excpeption building SessionFactory: " + ex.getMessage(), ex);
}
}
public static final ThreadLocal jawsSession = new ThreadLocal();
public static Session currentJawsSession() throws HibernateException {
Session s = (Session) jawsSession.get();
//Open a new Session, if this Thread has none yet
if (s==null) {
s = jawsSessionFactory.openSession();
session.set(s);
}
return s;
}
public static void closeJawsSession() throws HibernateException {
Session s = (Session) jawsSession.get();
jawsSession.set(null);
if (s!=null) {
s.close();
}
}
private static SessionFactory setupJawsSessionFactory () throws TaosException {
try {
Context context = new InitialContext();
Object obj = context.lookup("java:/HibernateFactory");
SessionFactory sessions = (SessionFactory)obj;
return sessions;
}
catch (NamingException ex) {
logger.debug("Naming exception. " + ex.getMessage());
throw new TaosException("Naming Exception. " + ex.getMessage());
}
}
}
method to execute query
Code:
public Vector getJawsJobs() throws TaosException {
Vector returnJobs = new Vector();
try {
Session session = HibernateUtility.currentJawsSession();
Transaction tx=session.beginTransaction();
List joblist = session.find("from JawsJob" );
Iterator jobs = joblist.iterator();
logger.debug("after iterator.");
while (jobs.hasNext()) {
JawsJob job = (JawsJob)jobs.next();
logger.debug("got jaws job: " + job.getJobName());
returnJobs.add(job);
}
tx.commit();
session.connection().close();
return returnJobs;
}
catch (HibernateException ex) {
logger.debug("Hibernate exception. " + ex.getMessage());
throw new TaosException("Hibernate Exception. " + ex.getMessage());
}
}