[英]In java spring hibernate 3.6.3 how to tell a method to wait until lock is aqured and how to retry a failed transaction?
In my spring application I am facing failed to acquire lock issue and transaction is getting failed.在我的 spring 应用程序中,我面临获取锁失败的问题并且交易失败。 It is not even rollbacking the transaction as database is not providing the lock.
它甚至没有回滚事务,因为数据库没有提供锁。 How to tell a method to wait until the lock is acquired?
如何告诉一个方法等待直到获得锁? I am using hibernate and mysql.
我正在使用 hibernate 和 mysql。
First of all, you have to use @Transactional
as method/class annotation in the case of spring.首先,在 spring 的情况下,您必须使用
@Transactional
作为方法/类注释。
By default, we have the propagation REQUIRED @Transactional(propagation = Propagation.REQUIRED)
.默认情况下,我们有传播 REQUIRED
@Transactional(propagation = Propagation.REQUIRED)
。 Spring checks if there is an active transaction, then it creates a new one if nothing existed. Spring 检查是否有活动事务,如果不存在则创建一个新事务。 Here you can find the explanation of spring transaction propagations.
在这里你可以找到 spring 交易传播的解释。
First, you have to take a look and analyze what you need there to use.首先,您必须查看并分析您需要在那里使用的内容。
Please tell us, where do you face with lock issues?请告诉我们,您在哪里遇到锁定问题? Probably you have to deal with the Isolation levels;
可能您必须处理隔离级别; We can deal with them at mySql, hibernate or spring level.
我们可以在mySql、hibernate或spring级别处理。 Here we need to know where you have configurations for isolation (mySql, hibernate or spring).
这里我们需要知道你在哪里有隔离的配置(mySql,hibernate或者spring)。
You can check if you need to update the lock timeout , using QueryHints
.您可以使用
QueryHints
检查是否需要更新锁定超时。
@QueryHints({@QueryHint(name = "javax.persistence.lock.timeout", value = "3000")})
public Optional<Customer> findById(Long customerId);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.