gpt4 book ai didi

java - 使用 toplink 基本查询提示时指定查询超时

转载 作者:行者123 更新时间:2023-12-01 05:57:18 25 4
gpt4 key购买 nike

对于 glassfish v2,我在网络上进行了搜索,但无论如何都找不到在使用 TopLink 基本查询提示时指定查询超时的信息。我们还有另一种选择来迁移到 EclipseLink,但这并不可行。

已经尝试过解决方案 http://forums.oracle.com/forums/thread.jspa?threadID=974732&tstart=-1但看起来可以设置超时值的DatabaseQuery实际上是Toplink的,而不是TopLink必需的。

除了查询提示之外,我们还有其他方法来指示 JDBC 驱动程序设置此超时值吗?我需要在查询的基础上而不是在系统的基础上执行此操作(这只是更改 DISTRIBUTED_LOCK_TIMEOUT 的值)

最佳答案

根据Toplink JPA的文档关于Query Hints :

You can use the following TopLink JPA hints (for more details on these settings please refer to the TopLink documentation)

  • fetchSize Takes an Integer. Allows the user to set the fetchSize of a TopLink query.
  • referenceClass Takes a class. Override the target class of the query.
  • cacheUsage Takes an Integer. Describes how TopLink makes use of the cache for querying objects.
  • refresh Takes a Boolean. Set to true if the cache should be refreshed from the database.
  • lockMode Takes an Integer. Set for Pessimistic Locking.
  • expression Takes a TopLink Expression object. Used for querying using TopLink API.
  • timeout Takes an Integer. Sets the the query timeout in milseconds.

所以我的理解是你应该能够做到这一点:

Query queryEmployeesByFirstName = em.createNamedQuery("findAllEmployeesByFirstName");
queryEmployeesByFirstName.setHint("timeout", new Integer(5000));

尚未测试。

关于java - 使用 toplink 基本查询提示时指定查询超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2478278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com