如何使用JPA和Hibernate设置默认查询超时? [英] How to set a default query timeout with JPA and Hibernate?
问题描述
我正在使用Hibernate对数据库进行一些大查询,有时会遇到超时问题.我想避免在每个Query
或Criteria
上手动设置超时.
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
.
我可以为Hibernate配置提供任何属性,为我运行的所有查询设置可接受的默认值吗?
Is there any property I can give to my Hibernate configuration that would set an acceptable default for all queries I run?
如果没有,如何在Hibernate查询上设置默认超时值?
If not, how can I set a default timeout value on Hibernate queries?
推荐答案
JPA 2定义了 javax.persistence.query.timeout 提示,以毫秒为单位指定默认超时. Hibernate 3.5(目前仍处于beta版)将支持此提示.
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.
另请参见 https://hibernate.atlassian.net/browse/HHH-4662
这篇关于如何使用JPA和Hibernate设置默认查询超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!