Hello:
I am trying to integrate my CMP Stateless Session Beans with Hibernate 3.1. My DB is MySQL 4.0.13 and I use JBoss 3.2.7. I want JBoss to handle the Tx so that i have configured Hibernate with the following properties through hibernate.cgx.xml
Quote:
<session-factory name="hibernate/HibernateFactory">
<property name="show_sql">true</property>
<property name="connection.datasource">java:/MySqlDS</property>
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="transaction.factory_class">org.hibernate.transaction.CMTTransactionFactory</property>
<property name="transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
<property name="connection.release_mode">auto</property>
<property name="transaction.flush_before_completion">true</property>
<property name="transaction.auto_close_session">true</property>
</session-factory>
My session bean has the following code.
Code:
try {
Session session = HibernateUtil.currentSession();
HrOrgLocations location = new HrOrgLocations();
location.setLocation( "New Location");
session.save( location );
}catch( Exception e ) {
handleException( e ); //set ctx.setRollBackOnly()
}
My HibernateUtil as follows
Code:
public class HibernateUtil {
static {
try {
// Create the SessionFactory
new Configuration().configure().buildSessionFactory();
} catch (HibernateException ex) {
throw new RuntimeException("Configuration problem: "+ ex.getMessage(), ex);
}
}
public static Session currentSession() throws HibernateException,NamingException {
InitialContext context = new InitialContext();
Object object = context.lookup( "hibernate/HibernateFactory" );
return ((SessionFactory)object).getCurrentSession();
}
}
Now the problem is that Connection is not getting closed. I am not calling session.close() in my bean code assuming that the property "transaction.auto_close_session" will close the session and the underlying connection at the end of the transaction. I have defined "max-pool-size" as 10 in the DS definition file for MySQL in Jboss and for the 11 th call for the Session Bean method, I am gettinng the exception that "No managed connection available".
I am sure that I am missing something since this seems to be a basic problem. Any pointers will be helpful.
thanks and regards,
-- Kannan.