cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Török Péter <tor...@Allround.net>
Subject PK generation problem: uniqueness constraint violated
Date Tue, 07 Aug 2007 14:55:49 GMT
Hello,
I have a small application with an Oracle DB schema containing a single sequence, to be used
by all tables (there aren't many of them). The sequence is created with this code:
 
CREATE SEQUENCE MY_SEQ

INCREMENT BY 1

START WITH 1

MINVALUE 1

MAXVALUE 999999999999999999999999999

NOCYCLE

NOORDER

CACHE 20; 

 
I tried to make Cayenne use this sequence by setting up my DB entities like this:
 
<db-entity name="CHANGE" schema="MY_SCHEMA">

    ...

    <db-key-generator>

        <db-generator-type>ORACLE</db-generator-type>

        <db-generator-name>MY_SEQ</db-generator-name>

        <db-key-cache-size>1</db-key-cache-size>

    </db-key-generator>

</db-entity>

(On the GUI, I selected "Custom Sequence" as PK Generation Strategy.)
Now, at some point in my app, I am about to create new Change data objects (with DataContext.newObject()).
All is fine as long as there is no more than 20 of them. But when there is more than 20, I
get the following error at commit:
 
org.apache.cayenne.CayenneRuntimeException: [v.2.0.3 May 6 2007] Commit Exception
        at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:1254)
        at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:1130)
        ...
Caused by: java.sql.SQLException: ORA-00001: unique constraint (MY_SCHEMA.CHANG_PK) violated
 
(PK is a primary key constraint.)
The "CACHE 20" in the sequence looked immediately suspicious, s I tried to modify it to 50,
then to change it to NOCACHE, but it made no difference.
I also tried to change the "Cached PK size" parameter in the Modeler (originally it was 0,
but I saw that this resulted in a generated SQL statement INCREMENT BY 20, which didn't look
consistent with the actual definition of the sequence above, so I changed the parameter to
1).
I am using Cayenne 2.0.3 and Oracle 9.2.
Any clues to what is the cause and how to fix (or avoid) the problem?
Thanks in advance,
Peter
 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message