繁体   English   中英

如何在 Spring JPA 中锁定两个 JPA 查询

[英]How to lock two JPA queries in Spring JPA

我有两个疑问:-

1. customerRepository.getCustomerList();
2. customerRepository.updateCustomerList();

我想在两者上实现锁定(事务的原子性),以便只允许单个线程(http 请求)在 JAVA 中执行该事务。

我不想使用类级别的同步块。

谢谢

可能某处有一个公共方法调用这两种方法(直接或间接)。 您可以使用@Transactional注释该方法,以强制数据库调用在一个事务中运行。

https://www.baeldung.com/transaction-configuration-with-jpa-and-spring

暂无
暂无

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

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