How can I find the jdbc connection timeout of a hibernate session
- by StevenWilkins
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.