Thursday, February 24, 2011

Hibernate generating IDs from a Sequence

on the Entity:

@Id
@SequenceGenerator(name="PRODUCT_PROID_GENERATOR", sequenceName="PRO_ID_SEQ")
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="PRODUCT_PROID_GENERATOR")
@Column(name="PRO_ID", unique=true, nullable=false, precision=12)
private long proId;

and on the DB:

CREATE SEQUENCE PRO_ID_SEQ MINVALUE 1 START WITH 1 INCREMENT BY 1;



funnily the values assigned are:
1050
50
100

here a decent explanation about hilo :
https://forum.hibernate.org/viewtopic.php?f=9&t=1005635&view=next



so adding allocationSize=1 to @SequenceGenerator brings the behaviour back to normal

No comments: