micronaut-data icon indicating copy to clipboard operation
micronaut-data copied to clipboard

Default JDBC repository interface should contain `findIdForUpdate`

Open mikehearn opened this issue 4 months ago • 4 comments

Feature description

Correct use of concurrency in an RDBMS often requires the use of SELECT ... FOR UPDATE but Micronaut makes doing the right thing less convenient than it should be. The default set of methods in CrudRepository should expose a method that locks the row.

mikehearn avatar Aug 14 '25 13:08 mikehearn

Maybe we can create a new annotation that will force it

dstepanov avatar Aug 14 '25 14:08 dstepanov

You mean changing the default for all find* methods? That would be a interesting feature. Maybe I'm just a power user but I kinda like to control locking individually, though. If you take locks when you don't mean to it's easy to accidentally deadlock.

mikehearn avatar Aug 14 '25 14:08 mikehearn

IMHO locks are hard core in DBs, so I don’t like default method like that. So you would need to write a proper method name or annotate the ordinary find methods

dstepanov avatar Aug 14 '25 15:08 dstepanov

Well any save or update method already takes locks, they can't be avoided. In many cases software just isn't correct if not using find...ForUpdate especially when working with entity objects instead of projections.

mikehearn avatar Aug 14 '25 16:08 mikehearn