简体   繁体   English

使用与默认情况不同的事务隔离来创建休眠事务

[英]Create hibernate transaction with transaction isolation different from default

I am using Hibernate 5.12.17 as an orm. 我正在使用Hibernate 5.12.17作为orm。 I am not using other java frameworks which interface with hibernate(So no Spring). 我没有使用其他与hibernate接口的Java框架(因此没有Spring)。

So the question is: how do i create a transaction which has the Isolation Level "Serializable"? 因此问题是:如何创建隔离级别为“可序列化”的事务?

I don't want to change the default Isolation for all my hibernate using code, I just have a few queries which need to run with a different isolation level from the rest of my app. 我不想使用代码更改所有休眠的默认隔离,我只需要执行几个查询,这些查询需要以与应用程序其余部分不同的隔离级别运行。

In this case you can use these ways: 在这种情况下,您可以使用以下方式:

  1. Use Query.lockMode(String alias, LockMode lockMode) . 使用Query.lockMode(String alias, LockMode lockMode) You can find in the reference at this link. 您可以在参考资料中找到链接。
  2. Use Session.load(Class theClass, Serializable id, LockMode lockMode) . 使用Session.load(Class theClass, Serializable id, LockMode lockMode) You can find the reference here . 您可以在此处找到参考。
  3. Use one of the Session.lock(..) methods. 使用Session.lock(..)方法之一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM