-->
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.  [ 7 posts ] 
Author Message
 Post subject: some times datasource conection not returned on sesion close
PostPosted: Wed Sep 08, 2004 2:42 am 
Newbie

Joined: Wed Sep 08, 2004 2:23 am
Posts: 4
Location: KL, Malaysia
Hibernate version: 2.1.4

Mapping documents:
<property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>
<property name="connection.isolation">4</property>
<property name="transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
<property name="transaction.manager_lookup_class">net.sf.hibernate.transaction.JBossTransactionManagerLookup</property>
<property name="jta.UserTransaction">UserTransaction</property>

Data Source Configuration :

<!-- pooling enhancement -->
<blocking-timeout-millis>500</blocking-timeout-millis>
<idle-timeout-minutes>5</idle-timeout-minutes>
<min-pool-size>10</min-pool-size>
<max-pool-size>50</max-pool-size>
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>

<!-- MySQL specific enhancement -->
<connection-property name="autoReconnect">true</connection-property>
<connection-property name="autoReconnectForPools">true</connection-property>
<connection-property name="useNewIO">true</connection-property>

Code between sessionFactory.openSession() and session.close():\
public static final ThreadLocal session = new ThreadLocal();
Session s = (Session) session.get();
if (s == null) {
try {
s = sessionFactory.openSession();
session.set(s);
} catch (Exception e) {
throw new HibernateException(e.getMessage());
}
}
// check if session is not connected
if (!s.isConnected()) {
logger.warn("Reconnecting hibernate session...");
s.reconnect();
}
level++;
return s;
closeSession :
public static void closeSession() {
level--;
if (level <= 0) {
Session s = (Session) session.get();
if (s != null && s.isOpen()) {
session.set(null);
try {
s.flush();
s.close();

} catch (HibernateException e) {
logger.warn(e.getMessage());
}
}
}
}

Full stack trace of any exception that occurs:

Name and version of the database you are using: MySql 4.0.18 (connector/J 3.0.14)

Debug level Hibernate log excerpt: We can see some times database connection are not returning to connection pool on session close. I beleive that session.close() will close the connection .. Is there any thing is wrong in my configuration ...
Your help is highly appreciatable.

Thanks,
Jack

_________________
Jack

"BE PROACTIVE"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 3:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
If an exception occurs during flush(), you do not close() the session.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 5:08 am 
Newbie

Joined: Wed Sep 08, 2004 2:23 am
Posts: 4
Location: KL, Malaysia
Gavin,

Thanks for your reply.
Okay now I will change it and i will place session.close in finally block.

Any how but I can't see any exception during flush. But I observed one thing , whenever there are multiple sessions opened then some sessions are not closing.

Once again thanks for your time.

Thanks,
Jack

_________________
Jack

"BE PROACTIVE"


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 5:24 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
You're somehow mismatching sessions references while opening multiple ones in your code
Hibernate sessions have no relationship with each other (not on connection at least)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 08, 2004 6:08 am 
Newbie

Joined: Wed Sep 08, 2004 2:23 am
Posts: 4
Location: KL, Malaysia
Hai Emmanuel,

Thanks for highlighting this.

Do you think there is any thing wrong in my code at Beans(calling sessions and closing) or configuration of session(Hibernate).

The opening session and closing session code is above. And here I am attaching my bean level code for your reference .

SessionBean :
Transaction tx = null;
try {
Session session = XXXSession.currentSession();
tx = session.beginTransaction();
Long id = (Long) session.save(rrd);
session.flush();
return id;
} catch (HibernateException e) {
logger.error("Unable to create reload request: " +
ExceptionUtils.getStackTrace(e));
throw new TestFacadeCreateException(e);
} finally {
XXXSession.closeSession();
}

Please advice ..

Thanks,
Jack.

_________________
Jack

"BE PROACTIVE"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 1:44 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Well, you never commit or rollback any transaction. This is pretty wrong ;-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 09, 2004 9:01 pm 
Newbie

Joined: Wed Sep 08, 2004 2:23 am
Posts: 4
Location: KL, Malaysia
Thanks Emmanuel,

Actually we have commit and rollback in our code .. when I copied to Forum I removed ... some code ..

It's okay, it seems we have find the root cause ... , we have a small problem in closeSession part.

Thanks to all , who have spent their valuable time.

_________________
Jack

"BE PROACTIVE"


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.