hibernate entity使用sequence方式时,生成值与sequence实际值不一致的问题
使用JPA生成的entity,使用注解方式标注,id生成方式为db2数据库的sequence。
但在使用过程中,sequence值为2208,插入后的id却为12000。且每次插入数据。
在使用http://blog.csdn.net/mypop/archive/2011/01/20/6155649.aspx 这个方法查看日志后,发现hibernate在取出sequence后,又使用SequenceHiLoGenerator类进一步生成id。
解决方式参照http://in3040.blog.163.com/blog/static/11670244320098281147597/ ,注解@SequenceGenerator中增加一项“allocationSize=1”,即:
@SequenceGenerator(name="ID_SEQ",sequenceName="IDSEQ",allocationSize=1)
这样id值与sequence取出值一致。