【发布时间】:2017-11-13 19:30:18
【问题描述】:
我需要在我的实现中使用@Lock:
@Lock(LockModeType.PESSIMISTIC_WRITE)
private Note findOneForUpdate(BigInteger id) {
return noteDao.findOne(id);
}
但其他消息来源说它应该在接口中:
@Repository
public interface NoteRepository extends JpaRepository<Note, BigInteger>, NoteDao {
@Lock(LockModeType.PESSIMISTIC_WRITE)
Note findOne(BigInteger id);
}
那么,第一个选项可能吗?我用 spring-boot-starter-data-jpa 1.5.3.RELEASE 试过了,但是锁不起作用。
【问题讨论】:
-
@Lock在 Spring Data JPA 存储库之外的任何东西上都不会做任何事情。此注释由 Spring Data JPA 读取,仅此而已。
标签: spring hibernate spring-boot transactions spring-data-jpa