Description
Iryna Tserlizhenka opened DATAMONGO-2102 and commented
It would be great to have ability to use java.util.Date as a version field for optimistic locking:
public class DateVersioned {
@Id
private String id;
@Version
private Date dateVersion;
...
}
So far I found a way to make it work with existing objects through converters (see reference URL for details), but not with new ones. When saying existing objects, I mean documents that already had dateVersion field in the DB before @Version
was applied.
When using converters for new objects the date version is stored in the DB as NumberLong, but queried as a date in optimistic lock clause. Therefore optimistic lock always fails.
Expected behavior: adding @Version
annotation on the Date field should be enough to make it work. Possibly we'll need some additional configuration like @Temporal
in JPA. The date fields should be stored in the DB as dates, not as numbers.
It would also be nice to update the documentation on types that can be used as a version. The current documentation does not include this information but mentions similarity to JPA where we can use Date mapped to timestamp for some providers
Affects: 2.0.10 (Kay SR10)
Reference URL: https://stackoverflow.com/questions/52604081/spring-optimistic-lock-for-mongodb-document-with-java-util-date-field