@SequenceGenerator allocationSize 'duplicate key error' issue @SequenceGenerator allocationSize 'duplicate key error' issue database database

@SequenceGenerator allocationSize 'duplicate key error' issue


You need to use the pooled-lo optimizer as it can inter-operate with other systems as well, or inserts issued from an administration console:

@Id@GenericGenerator(name = "sequenceGenerator", strategy = "enhanced-sequence",    parameters = {        @org.hibernate.annotations.Parameter(            name = "optimizer",             value = "pooled"),        @org.hibernate.annotations.Parameter(            name = "initial_value",             value = "1"),        @org.hibernate.annotations.Parameter(            name = "increment_size",             value = "5")    })@GeneratedValue(    strategy = GenerationType.SEQUENCE,     generator = "sequenceGenerator")private Long id;


Change hbm2ddl.auto configuration, set it to create then it will work as the sequence value used for assigning the id in the table depends on the previous stored sequence number, not a bug.

<property name="hbm2ddl.auto">create</property>