Spring 弹簧数据JPA锁定
我需要在我的实现中使用@Lock:Spring 弹簧数据JPA锁定,spring,hibernate,spring-boot,transactions,spring-data-jpa,Spring,Hibernate,Spring Boot,Transactions,Spring Data Jpa,我需要在我的实现中使用@Lock: @Lock(LockModeType.PESSIMISTIC_WRITE) private Note findOneForUpdate(BigInteger id) { return noteDao.findOne(id); } 但其他消息来源说,它应该在接口中: @Repository public interface NoteRepository extends JpaRepository<Note, BigInteger>, Not
@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);
}
@存储库
公共接口notepository扩展了JpaRepository,NoteDao{
@锁(锁模式类型。悲观写入)
注意findOne(biginger id);
}
那么,第一种选择可能吗?我用spring boot starter数据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);
}
@Lock(LockModeType.悲观写入)//不需要
私有便笺findOneForUpdate(BigInteger id){
returnnotedao.findOne(id);
}
@存储库
公共接口notepository扩展了JpaRepository,NoteDao{
@Lock(LockModeType.悲观_WRITE)//必需
注意findOne(biginger id);
}
@存储库类中需要锁批注
@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);
}
@Lock(LockModeType.悲观写入)//不需要
私有便笺findOneForUpdate(BigInteger id){
returnnotedao.findOne(id);
}
@存储库
公共接口notepository扩展了JpaRepository,NoteDao{
@Lock(LockModeType.悲观_WRITE)//必需
注意findOne(biginger id);
}
@Lock
锁定任何其他对象,那么Spring数据JPA存储库不会执行任何操作。此注释由Spring数据JPA读取,而不是其他任何内容。@Lock
对任何其他内容执行操作,则Spring数据JPA存储库不会执行任何操作。此注释由Spring数据JPA读取,而不是其他内容。