Why get unique constraint violation exception when set allocationSize as 50 in Microservice

Viewed 148

Environment:

Hibernate5.1, JPA1.8, Oracle12, Spring 4.3.9

Sequence:

CREATE SEQUENCE "SEQ_PROBLEM" MINVALUE 0 MAXVALUE 9999999999 INCREMENT BY 1 START WITH 1 CACHE 100 NOORDER NOCYCLE;

Entity Config:

@Id
@SequenceGenerator(name = "PROBLEM_ID_GENERATOR", sequenceName = "SEQ_PROBLEM", allocationSize = 50)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PROBLEM_ID_GENERATOR")
private long id;

Test Step:

  1. Start one server, and save the entity, success.
  2. Start the other server, and save the entity, I get the "unique constraint violation" error.

java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (******.PK_PROBLEM) violated

I checked the code, and the PooledOptimizer class do not apply the 50 sequences from oracle, so I guess that the second server cannot get the correct sequence number. As performance reason that I do not want to set the allocationSize as 1. Any ideas for this situation? thanks.

0 Answers
Related