spring-data-relational icon indicating copy to clipboard operation
spring-data-relational copied to clipboard

Bug?: `@Lock` on query methods does not add locking to query

Open koenpunt opened this issue 3 years ago • 3 comments

Before with JPA a repo method with @Lock would get the FOR UPDATE sql part added to the query.

But now with Spring R2DBC that's no longer the case.

@Lock(LockMode.PESSIMISTIC_WRITE)
suspend fun findForUpdateById(id: UUID): Cart?

koenpunt avatar Sep 21 '22 17:09 koenpunt

@koenpunt, Interesting, I just ran the test case under org.springframework.data.r2dbc.repository.query.PartTreeR2dbcQueryUnitTests#createQueryWithPessimisticWriteLock() in PartTreeR2dbcQueryUnitTests.java.java which matches with your usecase and the code seems to be generating the final query with the FOR UPDATE clause.

hariohmprasath avatar Sep 26 '22 06:09 hariohmprasath

Please provide a Minimimal Reproducable Example, preferable as a Github repository. Make sure to include the database, either as an in memory database or if that is not possible using Testcontainers.

schauder avatar Sep 26 '22 07:09 schauder

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues avatar Oct 03 '22 12:10 spring-projects-issues

I figured it out; we're using spring-boot-starter-data-r2dbc, which still uses the previous version of spring-data-r2dbc, which doesn't contain the pessimistic locking introduced in this commit.

koenpunt avatar Oct 10 '22 09:10 koenpunt