简体   繁体   中英

Spring data JPA locking

I need to use @Lock inside of my implementations:

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

But other sources say it should be in interfaces:

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

So, is first option possible? I tried it with spring-boot-starter-data-jpa 1.5.3.RELEASE, but lock did not work.

@Lock annotation is required in repository class

@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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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