0

We use a Spring Boot 2.5 with Java 17 and Postgres DB.

We have a method example() annotated with @Transactional(propagation = Propagation.NESTED).

Within example() method we use repository method "getData()" which has @Lock(LockModeType.PESSIMISTIC_READ).

@Transactional(propagation = Propagation.NESTED)
public int example(List<Integer> companyIds) {
    List<ExampleEntity> entityList = repository.getData(ids);

//rest of the method implementation...

    repository.flush();

    return someValue;
}
    @Lock(LockModeType.PESSIMISTIC_READ)
    @Query("select e from ExampleEntity e where e.companyId in :companyIds")
    List<ExampleEntity> getData(@Param("companyIds") final Integer companyIds);

My question is: Will the lock be released after executing example() method and nested transaction ends, or the lock will stay on until the parent transaction is being committed/rolled back? I ask this because I would like to keep the pessimistic lock as short as possible.

0 Answers0