开发者

How can I find the jdbc connection timeout of a hibernate session

开发者 https://www.devze.com 2023-02-01 00:25 出处:网络
I currently have a long running thread which uses a hibernate session to perform many updates.We currently have our c3p0 connection timeout set to 20 minutes and it\'s timing out sometimes because of

I currently have a long running thread which uses a hibernate session to perform many updates. We currently have our c3p0 connection timeout set to 20 minutes and it's timing out sometimes because of the number of updates we're performing.

The solution I have is to periodically return the connection to the pool via closing开发者_如何转开发 the session (we have hibernate configured this way) and get a new one. Upping the timeout is not desirable because the same pool is used for the entire application.

The problem is I don't know when to return the connection to the pool because I don't know what the timeout of the connection is. I know what the current setting is in our property file, but that can be changed without my knowledge at any time so it's fragile. Having a counter and returning the connection based on the number of updates I've performed is not ideal but could be my option of last resort.

I have a hibernate session, how can I retrieve the connection timeout of the jdbc connection which backs the session? Using the SessionFactory and SessionFactoryImpl classes are perfectly acceptable.


HibernateServiceMBean and StatisticsServiceMBean are the MBeans provided by Hibernate in context with JMX. HibernateService and StatisticsService are the implementation classes of these interfaces.

The HibernateServiceMBean contains several methods for Hibernate configuration properties like data-source, transaction strategy, caching, dialect etc.

The org.hibernate.cfg.Environment.C3P0_TIMEOUT is the property which indicates maximum idle time for C3P0 connection pool.


You cannot get back properties from SessionFactory or SessionFactoryImpl. Also if you are note using a jmx service Nayan's answer may not be useful. My suggestion,

import org.hibernate.cfg.Configuration;

Configuration.config();//reads all properties from hibernate.cfg.xml Properties props = Configuration.getProperties();// this will return the properties in hibernate.cfg.xml

So you can get any of the property value you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号