如何使用 JPA 和 Hibernate 设置默认查询超时? [英] How to set a default query timeout with JPA and Hibernate?

查看:92
本文介绍了如何使用 JPA 和 Hibernate 设置默认查询超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Hibernate 对我的数据库进行一些大型查询,有时我会遇到超时.我想避免在每个 QueryCriteria 上手动设置超时.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆