In the meantime I found the solution (or rather a workaround...) in an earlier mail to this mailing list... Sorry for bothering you and thanks to Philip Miller for the hint :-)
(For reference, his original mail is here:
http://objectstyle.org/cayenne/lists/cayenne-user/2007/02/0104.html)
However, setting the primary key cache to 1 didn't help in my case, Cayenne still used PK sequence values in batches of 20.
The only working solution for me was to set INCREMENT BY to 20 with NOCACHE on the DB side.
Is it possible that the cache size 20 is hardcoded somewhere in Cayenne and setting it in the modeler doesn't have an effect (or am I totally misunderstanding something here about how Cayenne is supposed to work)?
Thanks,
Peter
-----Original Message-----
From: Török Péter [mailto:torok..llround.net]
Sent: Tuesday, August 07, 2007 4:56 PM
To: use..ayenne.apache.org
Subject: PK generation problem: uniqueness constraint violated
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
This archive was generated by hypermail 2.0.0 : Fri Aug 10 2007 - 04:22:47 EDT