users@glassfish.java.net

Toplink ORACLE sequence problem

From: <glassfish_at_javadesktop.org>
Date: Mon, 01 Dec 2008 05:49:33 PST

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:

    @Id
    @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.
[Message sent by forum member 'asantiago' (asantiago)]

http://forums.java.net/jive/thread.jspa?messageID=319341