-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How to close the session/connnectin in a managed environment
PostPosted: Tue Mar 07, 2006 6:21 am 
Newbie

Joined: Tue Mar 07, 2006 5:51 am
Posts: 11
Location: India
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.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 07, 2006 6:34 am 
Newbie

Joined: Tue Mar 07, 2006 5:51 am
Posts: 11
Location: India
Hello:

!! Sorry to bother the community !!

There was a line of code in the bean which was getting the JDBC Connection thru direct datasource look up and that Connnection was not getting closed which was causing the problem.

thanks and regards,

-- Kannan.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.