简体   繁体   English

In java spring hibernate 3.6.3 如何告诉方法等待锁被获取以及如何重试失败的事务?

[英]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.

相关问题 Spring Data:如何在一个事务中锁定一行并使其他事务等待其释放? - Spring Data: How to lock a row in a transaction and make other transactions wait until it is released? 如何使用Java持久性重试锁定等待超时? - How to retry a lock wait timeout using java persistence? 如何等待,直到Java中的另一个线程释放了锁? - How to wait until a lock is released in another thread in Java? 超过了锁定等待超时; 尝试使用spring和Mysql重新启动事务Java - Lock wait timeout exceeded; try restarting transaction Java with spring and Mysql 如何告诉 Camel 等到副本结束? - How to tell Camel to wait until the end of the copy? 如何在Java Spring和Hibernate中的单个事务中管理2个DAO方法? - How to manage 2 DAO methods in a single transaction in Java Spring and Hibernate? 超过了锁定等待超时; 尝试在spring_Hibernate_Mysql中重新启动事务 - Lock wait timeout exceeded; try restarting transaction in spring_Hibernate_Mysql Spring hibernate,如何在事务提交或事务回滚后调用一些方法 - Spring hibernate , how to call some method after transaction commit or transaction rollback 如何在休眠/弹簧模式下使用锁定共享模式? - How to use LOCK IN SHARE MODE with hibernate/spring? Java中如何使用锁来等待特殊条件? - How to use a lock in Java to wait for the special condition?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM