This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
The connection pool should be able to recover any inactive connections, but all the active connections would drop as soon as the database goes down. This means that any code that is calling Hibernate will get an exception. It won't be able to recover from a connection dropped on an active connection. You will have to either manage that in the application, or show error to user.
Thanks Friends, but I am little confused with the answer, you have mentioned that most pools can detect unavailable db and recover from it soon, but does it reconnect to db again if it db comes up and if yes what is underlying process/ api which does it and can we configure this in hibernate properties or cfg file?
Joined: Mar 22, 2005
That depends on the connection pool being used. To that extent I disagree with what Jayesh said - there are certainly pool implementations out there that know how to recover from an unavailable DB. I don't know if the default pool used by Hibernate can, but it's easy enough to test.
Maybe I didn't explain myself correctly. By "active" connections, I mean connections that are currently in an transaction. If the database goes down during a transaction, the transaction will roll back on the server, and Hibernate will most probably get an exception from underlying JDBC provider. Unless the JDBC provider has some way of keeping the transaction on the client side, and replaying it when the database comes back up, Hibernate cannot do anything
Now, it gets a little fuzzy, because Hibernate internally does caching in the session, and doesn't go to the database until the session is flushed. Atleast, I'm very fuzzy about it. Generally, the assumption that I make that if there is some catastrophic failure that causes the database to go down, or cause the connection to terminate, the Hibernate session will throw an exception.
Thanks a lot Ulf Dittmer and Jayesh, you have mentioned about a condition where a transaction is happening, but if we talk about a system in stand by mode, can hibernate reconnect to db in that mode as well?
Please suggest and if you know something about if we can control this mechnanism, please do write that too..