Reputation: 1122
I am using Table Generator strategy for generating primary keys. Recently I upgraded to Hibernate 5 and i am getting issue of primary keys getting generated negative values. Database: PostgreSQL 9.3, Hibernate 5.0.2
Here are my annotations look like.
@Id
@TableGenerator(name = "EMP_ID",
table = "ID_GENERATOR",
pkColumnName = "GEN_KEY",
valueColumnName = "GEN_VALUE",
pkColumnValue = "EMP_ID",
allocationSize = 10,
initialValue = 1)
@GeneratedValue(strategy = GenerationType.TABLE, generator = "EMP_ID")
@Column(name = "EMP_ID", unique = true, nullable = false)
private long empId;
Can someone please help me out here?
Upvotes: 1
Views: 793
Reputation: 1
Check if GEN_VALUE in database is less than initialValue property in the entity class generate this issue, for example:
If the column value GEN_VALUE is 0 and initialValue is 1, it generates negative value. To Solve the issue, equal initialValue with GEN_VALUE.
Regards,
Upvotes: 0