Hibernate provides next generated id 32768 and so on 65536, 98304

佐手、 提交于 2019-12-13 02:37:51

问题


EMPLOYEE.java

@Entity
@Table(name="EMPLOYEE")
public class Employee implements Serializable {

@Id
@GeneratedValue( strategy = GenerationType.TABLE)

EMPLOYEE (TABLE)

1   3/13/2013   911 Jack    Bauer

32768   3/13/2013   911 Jack    Bauer

65536   3/13/2013   911 Jack    Bauer

98304   3/13/2013   911 Jack    Bauer

HIBERNATE_SEQUENCES(TABLE) HOLDING CORRECT NUMBER

EMPLOYEE    4

回答1:


@TableGenerator(name="tabgen",table="employee-id",pkColumnName="name",valueColumnName="value",allocationSize=1)
@GeneratedValue(strategy=GenerationType.TABLE, generator="tabgen")

however, its always better to use increment or sequence instead of table generation if you need the ids to be in sequence. the random ids which u see with default table strategy is because of the need to support multiple threads all simulteneously trying to insert.



来源:https://stackoverflow.com/questions/15393534/hibernate-provides-next-generated-id-32768-and-so-on-65536-98304

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!