views:

245

answers:

2

I am running Spring + hibernate 3 + c3p0. Upon start up, if the database is down an exception is thrown after about 10 mins. Until then the program is blocked... I dont include spring xml, hibernate configuration etc, since it is a fairly common problem and if a solution exists it must be a standard straighforward way. If not i can trim the crucial code and configuration and paste it here. Does anybody know anything about it? Thanks in advance.

A: 

It's most likely not related to Hibernate / Spring per se; database connection pool is responsible for dealing with connections.

  1. What are your C3P0 settings?
  2. What database / driver are your using? Are there any driver-specific settings causing driver itself to wait / retry before reporting an error?
  3. Does "database down" mean "completely down"? Or could this be caused by some sort of socket timeout?

Update (based on OP clarification below):

DriverManager.setLoginTimeout() is not used by the oracle driver. OracleDataSource has its own loginTimeout setting instead.

ChssPly76
You are right. I just may have used a wrong ip in the connection url. See my edit for what i essentially need.
Paralife
A: 

To clarify:

What I essentially need is to know if there is a wrapper in c3p0 or hibernate, or even spring, around the DriverManager.setLoginTimeout() function. Or a feature that offers me this functionality. The wrapper could be through a setting or something. I just want to get an exception if i havent connected to the datasource in X seconds, no matter the cause (socket, database, bad weather). And I want to find a place to set this X. To make things worse, Oracle driver , which is the driver i am using, does not implement setLoginTimeout() so I cant use it directly. I ve come to realize there is no way to solve it, but to manually spawn a timer thread of my own. Anybody can verify the above situation? Thanks a lot.

Paralife
`DriverManager.setLoginTimeout()` is not used by the oracle driver. `OracleDataSource` has its own loginTimeout setting instead: http://download.oracle.com/otn/utilities_drivers/jdbc/111060/doc/javadoc/oracle/jdbc/pool/OracleDataSource.html#setLoginTimeout(int)
ChssPly76
Thanks a lot. This solved my problem. Can you post an answer so I can mark it?
Paralife
You're welcome. I've updated my answer above, thanks.
ChssPly76