Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a default query timeout with JPA and Hibernate?

I am doing some big queries on my database with Hibernate and I sometimes hit timeouts. I would like to avoid setting the timeout manually on every Query or Criteria.

Is there any property I can give to my Hibernate configuration that would set an acceptable default for all queries I run?

If not, how can I set a default timeout value on Hibernate queries?

like image 968
malaverdiere Avatar asked Jan 20 '10 13:01

malaverdiere


People also ask

How do I set hibernate timeout?

hibernate. loader. Loader and set the timeout in doQuery. Use AOP, e.g. Spring, to return a proxy for Session; add advice to it that wraps the createQuery method and sets the timeout on the Query object before returning it.

Which property can be used to define a timeout for a query?

The QueryTimeOutUtil class provides setQueryTimeOut methods that defines the timeout of: SQL statements.

What is Hibernate timeout?

Hibernate Timeout lets you set the amount of time the printer waits after a print job is processed before it goes into a reduced power state.


1 Answers

JPA 2 defines the javax.persistence.query.timeout hint to specify default timeout in milliseconds. Hibernate 3.5 (currently still in beta) will support this hint.

See also https://hibernate.atlassian.net/browse/HHH-4662

like image 61
Hardy Avatar answered Oct 19 '22 20:10

Hardy