Hibernate does not retrieve the next value in database sequence, but a much larger value.

Solution Unverified - Updated -

Issue

We have just discovered that in using hibernate, we are not getting the next value in our database sequence.

The code appears as such:

@Id
@Column(name = "ID", nullable = false)
@GeneratedValue(generator = "runsheetSeq", strategy = GenerationType.SEQUENCE)
@SequenceGenerator(name = "runsheetSeq", sequenceName = "RUNSHEET_SEQ", allocationSize = DRVModelConstants.DEFAULT_SEQUENCE_ALLOCATION_SIZE)
private Long runsheetID = null;

Looking at our database sequence, RUNSHEET_SEQ

CREATED 15/DEC/08
LAST_DDL_TIME 15/DEC/08
SEQUENCE_OWNER AXIOM
SEQUENCE_NAME RUNSHEET_SEQ
MIN_VALUE 1
MAX_VALUE 999999999999999999999999
INCREMENT_BY 1
CYCLE_FLAG N
ORDER_FLAG N
CACHE_SIZE 20
LAST_NUMBER 913718

However, the generated id values turn out like '18265760'. That is a huge jump.

Whenever we generate an entry, not through hibernate, that uses the same sequence, we do get the correct value.

What could be the cause of this? For the moment, there are no collisions since the numbers are just too far apart. However, when the sequence does reach the hibernate generated number, it would start to fail.

Environment

JBoss Enterprise Application Platform (EAP) 5.1.2

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase of over 48,000 articles and solutions.

Current Customers and Partners

Log in for full access

Log In
Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.