I use the code above to generate id:
@Id
@GeneratedValue(generator = "seqq")
@SequenceGenerator(name = "seqq", sequenceName = "seqq", allocationSize = 20, initialValue = 1)
public long getId() {
return id;
}
I also updated persistence.xml:
<property name="hibernate.id.new_generator_mappings" value="true"/>
and updated ddl in the database:
CREATE SEQUENCE seqq
INCREMENT 20
MINVALUE 1
MAXVALUE 9223372036854775807
START 9171
CACHE 1;
Due to this, allocSize = 20 matches the increment value. However, I get arbitrary errors saying that a duplicate key value violates the unique "myobjects_pkey" constraint. Often this error occurs after the first save of the trial version. It seems that hibernate is trying to save the object with the same id. However, START ensures that the row is larger than any existing row in the table identifier. How to fix duplicate constraint error?
source
share