在我的 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”
。
是否有一个选项可以仅在一个请求中执行“选择更新”
?
问候 塞德里克
最佳答案
要禁用后续锁定:
- 升级到 Hibernate 5.2.1
- 将数据库升级到 12c 并使用
Oracle12cDialect
,或者设置HINT_FOLLOW_ON_LOCKING
查询提示为false
参见here了解更多信息。
关于java - hibernate : select for update in two request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50177586/