This is poorly documented, many of the solutions here and other sites relate to older versions of sleep mode, where the HiLo sequence generator was installed by default. But after the investigation, I found that the main reason is that JBoss EAP 6 installs
hibernate.id.new_generator_mappings=true
by default, which uses org.org.hibernate.id.enhanced.SequenceStyleGenerator instead of the old version.
The default value for the Hibernate SequenceStyleGenerator is 1 (check the code!), However the JPA overrides the increment value in this generator to 50. This means that the generator scans the next sequence and stores a cache of 50 identifiers to use, starting from nextval - 49. When they exhausted, the generator reads the next sequence from the oracle and repeats the process. Therefore, when the first series of identifiers is exhausted, we begin to see duplicate keys.
So the resolution is:
1) Define an Oracle sequence with an incremental value of 50 to comply with the JPA default
CREATE SEQUENCE MY_SEQ START WITH 50 MAXVALUE 9999999999999999999 INCREMENT BY 50 NOCYCLE;
or
2) Add allocSize = 1 to the @SequenceGenerator annotation - this will make SequenceGenerator go back to read the next value from the oracle sequence for each required identifier (with potential impact)
@SequenceGenerator(name = "USERS_ID_GENERATOR", sequenceName = "MY_SEQ", allocationSize = 1)
or
3) define the sequence of Oracle INCREMENT with a different value and make sure matchSize matches.
He answered my own question in the hope of helping others who were faced with this problem.
source share