redis-om-spring
redis-om-spring copied to clipboard
Spring `@Version` optimistic locking annotation is unsupported
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 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.
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/