Skip to main content

Toplink ORACLE sequence problem

2 replies [Last post]
Joined: 2006-11-09

Hi all,

I don't know if this is the right place (please forward me if I'm wrong).

I have a table CAMP using a sequence for its ID.
Also, I have modified the automatically generated entity class to use the sequence as follows:

@Column(name = "ID_CAMP", nullable = false)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator="CAMP_SEQUENCE_GENERATOR")
@SequenceGenerator(name="CAMP_SEQUENCE_GENERATOR", sequenceName="CAMP_ID_CAMP_SEQ")

All that is fine, and if I create a new object and persist it works fine.

The problems is, initially, once I created the table I need to populate it with some SQL-INSERT sentences, which increases the last sequence value (to 50).
Later, when I create another instance and try to persist it, JPA doesn't detects well the last ID number and a duplicate key error is returned. The strange thing is it remembers that value between sessions, next "class" returns me errors with ID=3, ID=4, etc.

Thanks in advice for any help.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2008-05-20

set the Element allocationSize (to 1) on the annotation SequenceGenerator

regards franz

Joined: 2006-11-09

Thanks Franz, it works fine.