繁体   English   中英

Spring 数据 JPA 锁定

[英]Spring data JPA locking

我需要在我的实现中使用@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 注释

@Lock(LockModeType.PESSIMISTIC_WRITE) // not required
private Note findOneForUpdate(BigInteger id) {
    return noteDao.findOne(id);
}

@Repository
public interface NoteRepository extends JpaRepository<Note, BigInteger>, NoteDao {
    @Lock(LockModeType.PESSIMISTIC_WRITE) // required
    Note findOne(BigInteger id);
}

暂无
暂无

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

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