Mike Mike - 1 year ago 247
Java Question

How to configure connection timeout in hibernate?

I'm using Hibernate v4.1.4.final.jar using Java 1.7 to connect to Oracle 10g server. And this is a standalone java program.

Unfortunately, my query takes more than 30 minutes to run. I want to know where I can configure connection time out & read time out so that while running this standalone program, it will not time out and throw error?


Answer Source

There are a few options that you can try:

  1. If the jdbc driver that you use support timeout function and can be configured through property, then you can pass on the property using: hibernate.connection.<propertyname>
  2. Use external connection provider such as c3p0 or DBCP, and control the timeout as those external provider support.
  3. Configure your hibernate to use DataSource instead of plain Connection and control timeout through that.

The closest property that I can find for Oracle driver is oracle.jdbc.ReadTimeout property. So in your hibernate configuration, the whole name will be hibernate.connection.oracle.jdbc.ReadTimeout..hope this works for you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download