redis-om-spring icon indicating copy to clipboard operation
redis-om-spring copied to clipboard

Spring `@Version` optimistic locking annotation is unsupported

Open DinkoTontchev opened this issue 3 years ago • 2 comments
trafficstars

To easily reproduce, modify com.redis.om.spring.annotations.document.fixtures.Company to add a Spring @Version annotation like so:

  @Version
  Long version;

then run your existing test com.redis.om.spring.annotations.document.BasicRedisDocumentMappingTest:testAuditAnnotations() and observe the following error:

org.springframework.dao.DuplicateKeyException: Cannot insert existing object with id 01G5MB6GH63J2JKTWEZXN6J5WC!. Please use update.

It seems your implementation of CRUD repository is not updating the version field therefore causing the spring method deciding wether an object isNew to treat current as new since version = null.

DinkoTontchev avatar Jun 15 '22 18:06 DinkoTontchev

@DinkoTontchev Spring Data Redis doesn't support @Version and since we extend SDR neither do we at the moment. I'll have to take a look at whether it makes sense with Redis. I'm sure there is a reason they didn't implement it in SDR, I'll comment after I do some research.

bsbodden avatar Jun 28 '22 04:06 bsbodden

Potentially follow Spring Data Mongo lead https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mongo-template.optimistic-locking. Perhaps backed by https://redis.io/commands/watch/

bsbodden avatar Jul 04 '22 15:07 bsbodden