Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 弹簧数据JPA锁定_Spring_Hibernate_Spring Boot_Transactions_Spring Data Jpa - Fatal编程技术网

Spring 弹簧数据JPA锁定

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:

@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读取,而不是其他内容。