@Version is not being incremented in Spring mongo

groovy, java, spring, spring-mongo

Solution

I think you are using:

javax.persistence.Version 

Check your imports, @Version is part of javax.persistence (JPA) and has no relation to mongodb.

http://docs.spring.io/spring-data/mongodb/docs/1.5.0.RELEASE/reference/htmlsingle/ Unluckily, there is no hint to @Version in the spring data mongodb reference.

You should import org.springframework.data.annotation.Version for entity version information. See https://github.com/spring-projects/spring-data-mongodb/blob/1.5.x/spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/PersonWithVersionPropertyOfTypeInteger.java

Problem

I have added @Enableauditng as an annotation but @version is not incrementing the version on its own. I have @LastModifiedDate, which is being updated but not the @version. Am i doing somehting wrong. I am calling mongoTemplate.save(object) to againg and again. Please advice

Original source