---
title: "转hibernate entity使用sequence方式时，id增量50且与sequence值不一致的问题 "
author: "pipe"
date: "2012-05-29T15:31:58Z"
tags: []
categories: ["开源软件"]
slug: "hibernate-entity-sequence-id-50-sequence"
draft: false
lastmod: "2012-05-29T15:31:58Z"
id: 1543986
url: "https://pipe.iteye.com/blog/1543986"
---

使用JPA生成的entity，使用注解方式标注，id生成方式为Oracle数据库的sequence。
 
但在使用过程中，sequence值为228，插入后的id却为11300。且每次插入数据，id值增加50，sequence值仍然增加1。
 
 
 
在使用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取出值一致，且不再增50。