How can I get Hibernate to run version 1 column for new objects?

Does anyone know if it is possible to force Hibernate to use 1 for the version (optimistic lock field) of a new object instead of zero? My application previously used Eclipselink, which starts at 1, and the change causes some problems.

I use JPA, but expect any solution to be Hibernate specific (hopefully the property in persistence.xml!).

+5
source share
1 answer

Good question, and it is not explicitly mentioned in the documents ( although it hints that this is possible ). I also could not find any tests for this scenario, so this could be a good improvement for the Hibernate test suite; -)

In any case, Hibernate will work as you would expect if you map your property @Versionto the start value:

@Version private int version = 1;
+7
source

All Articles