0

I am running into this really weird issue where an oracle sequence returns very different values when issued from java/Hibernate vs SqlDeveloper tool.

@SequenceGenerator(name = "PARAM_ID_SEQUENCE", initialValue = 10, allocationSize = 30, sequenceName = "PARAM_ID_SEQUENCE")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PARAM_ID_SEQUENCE")
@Column(name = "PARAMETER_ID")

The above returns 1177248345. I turned the loglevel to trace to see the actual query being issued and it is: select SPS_PARAM_ID_SEQUENCE.nextval from dual. Now I issue the very same query against the same sequence from sql developer tool and it returns: 39241615 which is 2 orders of magnitude lesser! Also, this is the accurate value I would expect.

CREATED 03-OCT-14
LAST_DDL_TIME   25-JAN-18
SEQUENCE_OWNER  API
SEQUENCE_NAME   PARAM_ID_SEQUENCE
MIN_VALUE   1
MAX_VALUE   9999999999999999999999999999
INCREMENT_BY    1
CYCLE_FLAG  N
ORDER_FLAG  N
CACHE_SIZE  20
LAST_NUMBER 39241624
PARTITION_COUNT 
SESSION_FLAG    N
KEEP_VALUE  N

I confirmed that both are issuing requests on the same environment against the same database schema etc, but for some reason Hibernate gets a much higher value. Has anyone faced a similar issue. Is hibernate "padding" the sequence somehow?

Abe
  • 8,623
  • 10
  • 50
  • 74
  • 1
    Please have a look at "https://stackoverflow.com/questions/12745751/hibernate-sequencegenerator-and-allocationsize". If I get your problem right you can fix it while setting "hibernate.id.new_generator_mappings=true". Or you can set allocationSize = 1 at the @SequenceGenerator annotation. – Stefan Großmann Jan 29 '18 at 15:33
  • @StefanGroßmann Yes indeed this seems to be the issue. Thank you! – Abe Jan 29 '18 at 16:34

0 Answers0