如何使用 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(目前仍处于测试阶段)将支持此提示.
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屋!