Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is not well documented, many of the solutions on here and other sites relate to older versions of hibernate where the HiLo sequenceGenerator was the default. But after investigation I found the underlying cause is that JBoss EAP 6 sets</p> <pre><code>hibernate.id.new_generator_mappings=true </code></pre> <p>by default, which uses an org.org.hibernate.id.enhanced.SequenceStyleGenerator instead of the older version.</p> <p>The Hibernate SequenceStyleGenerator default increment is 1 (check the code!), however JPA overrides the increment value in this generator to 50. This means that the Generator looks at the sequence nextval and keeps a cache of 50 ids to use, starting from nextval - 49. When these are exhausted the generator reads the next sequence from oracle, and repeats the process. So once the first series of ids are exhausted we start seeing duplicate keys.</p> <p>So the resolution is:</p> <p>1) Either define your Oracle sequence(s) with an increment value of 50 to match the JPA default</p> <pre><code>CREATE SEQUENCE MY_SEQ START WITH 50 MAXVALUE 9999999999999999999 INCREMENT BY 50 NOCYCLE; </code></pre> <p>or</p> <p>2) Add allocationSize=1 to the @SequenceGenerator annotation - this forces the SequenceGenerator to go back to read the next value from the oracle sequence for each ID it requires (with a potential performance impact)</p> <pre><code> @SequenceGenerator(name = "USERS_ID_GENERATOR", sequenceName = "MY_SEQ", allocationSize = 1) </code></pre> <p>, or</p> <p>3) define the Oracle sequence INCREMENT BY some other value, and ensure the allocationSize matches.</p> <p>Answered my own question in the hope of helping others that strike this issue.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload