-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate session not recovering after connection drop.
PostPosted: Wed May 16, 2007 7:09 am 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
Hi everyone,

We have an issue in Production right now. If our DMZ Server drops the connection to the Database the Hibernate Session fails, once the connection is re-established Hibernate doesn’t reinitiate the session. So even though the connection is back again Hibernate can no longer talk to the Database. The only way around this is to start the Tomcat Server, and everything starts to run fine again.
Is there any kind of configuration we can do for Hibernate so that it will try and reinitiate the connection to the database in the event of it being lost?

Any help, thoughts, comments, would be much appreciated!

Cheers.
Adam.G

_________________
Everytime you get an answer to your question without giving credit; god kills a kitten. :(


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 8:39 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
any chance you can use AoP to check the status of the session at the start of each hibernate method call, and if there is a problem, recreate a new session, and clean up any old junk ones.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 9:11 am 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
AoP isn't an ideal solution in this situation, there's no Hibernate config for trying to re-establish a connection if the connection to the database is temporarily lost?

_________________
Everytime you get an answer to your question without giving credit; god kills a kitten. :(


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 4:00 pm 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
bump :(

_________________
Everytime you get an answer to your question without giving credit; god kills a kitten. :(


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 6:34 pm 
Expert
Expert

Joined: Wed Apr 06, 2005 5:03 pm
Posts: 273
Location: Salt Lake City, Utah, USA
Unless I'm not understanding your problem, what you are really dealing with is a problem that the connection pool should be handling. For example, if you are using c3p0, there are quite a few settings that you can use to avoid getting broken connections in a Session:

http://www.mchange.com/projects/c3p0/index.html

Quote:
maxIdleTime
Default: 0
Seconds a Connection can remain pooled but unused before being discarded. Zero means idle connections never expire.


Quote:
idleConnectionTestPeriod
Default: 0
If this is a number greater than 0, c3p0 will test all idle, pooled but unchecked-out connections, every this number of seconds.


Quote:
testConnectionOnCheckin
Default: false
If true, an operation will be performed asynchronously at every connection checkin to verify that the connection is valid. Use in combination with idleConnectionTestPeriod for quite reliable, always asynchronous Connection testing. Also, setting an automaticTestTable or preferredTestQuery will usually speed up all connection tests.


Quote:
testConnectionOnCheckout
Default: false
Use only if necessary. Expensive. If true, an operation will be performed at every connection checkout to verify that the connection is valid. Better choice: verify connections periodically using idleConnectionTestPeriod. Also, setting an automaticTestTable or preferredTestQuery will usually speed up all connection tests.


As far as I know, there is no built-in way to recover a session if the connection gets dropped while the session is open. So if it's critical to be able to recover, you will probably have to explicitly handle that exception and retry (or whatever your recovery strategy is) with a new session.

Hope that helps.

_________________
nathan


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 17, 2007 3:35 am 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
Thanks very much Nathan, after a little searching I actually found c3p0 on my own, I'm gonig to have a play around with it and see if it could be a viable solution for PROD. Cheers for the help.

_________________
Everytime you get an answer to your question without giving credit; god kills a kitten. :(


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