gpt4 book ai didi

java - hibernate : select for update in two request

转载 作者:行者123 更新时间:2023-11-30 06:11:18 24 4
gpt4 key购买 nike

在我的 springBoot 项目中,我使用 hibernate 来获取 Oracle 数据库上的

在我的交易中,我执行以下代码:

Query q = em.createQuery("SELECT m FROM myTablem WHERE foo= :cat");
q.setParameter("cat", myValue);
q.setMaxResults(1);

//use pessimistic lock
//With Oracle, the select is a 'select for update' request
q.setLockMode(LockModeType.PESSIMISTIC_WRITE);

//set hibernate timeout to 0
//With Oracle, the 'select for update' is transformed in 'select for update nowait'
q.setHint("javax.persistence.lock.timeout", 0);

List<Msisdn> msisdns = q.getResultList();

我想在我的数据库上执行“选择更新”。但是使用这段代码,hibernate 执行两个请求:

Hibernate: select * from ( select m..... from myTablem m cross join categorie_critere categoriec1_ where m.foo=... ) where rownum <= ?

Hibernate: select ce_code_abpq from m where idpk1 =? and idpk2 =? and idpk3 =? for update nowait

在第一个请求中,hibernate 执行 select 请求。在第二个请求中,hibernate 对所选元素调用“select for update”

是否有一个选项可以仅在一个请求中执行“选择更新”

问候塞德里克

最佳答案

要禁用后续锁定:

  1. 升级到 Hibernate 5.2.1
  2. 将数据库升级到 12c 并使用 Oracle12cDialect,或者设置 HINT_FOLLOW_ON_LOCKING查询提示为 false

参见here了解更多信息。

关于java - hibernate : select for update in two request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50177586/

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