开发者

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

开发者 https://www.devze.com 2023-02-07 00:57 出处:网络
Does anyone know if it is p开发者_开发百科ossible to get Hibernate to use 1 for the version (optimistic locking field) of a new object instead of zero? My application previously used Eclipselink which

Does anyone know if it is p开发者_开发百科ossible to get Hibernate to use 1 for the version (optimistic locking field) of a new object instead of zero? My application previously used Eclipselink which starts at 1 and the change is causing some problems.

I am using JPA but expect any solution to be Hibernate specific (a property in persistence.xml hopefully!).


Good question, and it's not explicitly mentioned in the docs (even though it hints that it's possible). I also wasn't able to find any tests for this scenario, so, it may be a good improvement for the Hibernate test suite ;-)

Anyway, Hibernate will work as you expect if you map your @Version property with a starting value:

@Version private int version = 1;
0

精彩评论

暂无评论...
验证码 换一张
取 消