I found the problem. I was using MAX instead of SEQUENCE and table is filled up with a few hundred rows. ORACE_SEQUENCE was not used during this time. Because this was not in use, this (sequence)number was so low and when I started using SEQUENCE, the application is throwing PrimaryKey violation! Naturally. Now I need to bump up the sequence so that it is just equal to the number of rows currently in the table and use SEQUENCE instead of MAX.
Thanks for all your help. -----Original Message----- From: Shiva P. Kodityala [mailto:[EMAIL PROTECTED] Sent: Thursday, August 04, 2005 11:55 AM To: [email protected] Subject: RE: [castor-user] DuplicateIdentityException Thank you for the info. -----Original Message----- From: Ralf Joachim [mailto:[EMAIL PROTECTED] Sent: Thursday, August 04, 2005 11:02 AM To: [email protected] Subject: Re: [castor-user] DuplicateIdentityException Hi Shiva, the keygenerator you need in your mapping depends on how your tables are setup as this defines how oracle sets your identities. E.g. if you setup tables as follows: CREATE TABLE TAB_PCV_LIEFERANT ( PCLI_ID NUMBER ( 10,0) NULL, PCLI_NAME VARCHAR2 ( 25) NULL, TABLESPACE TBL_FIM1_PPT / ALTER TABLE TAB_PCV_LIEFERANT ADD PRIMARY KEY (PCLI_ID) USING INDEX TABLESPACE IDX_FIM1_PPT / CREATE SEQUENCE SEQ_PCV_LIEFERANT MAXVALUE 2147483647 INCREMENT BY 1 START WITH 1 / CREATE TRIGGER TRG_PCV_LIEFERANT BEFORE INSERT OR UPDATE ON TAB_PCV_LIEFERANT FOR EACH ROW DECLARE iCounter TAB_PCV_LIEFERANT.PCLI_ID%TYPE; cannot_change_counter EXCEPTION; BEGIN IF INSERTING THEN Select SEQ_PCV_LIEFERANT.NEXTVAL INTO iCounter FROM Dual; :new.PCLI_ID := iCounter; END IF; IF UPDATING THEN IF NOT (:new.PCLI_ID = :old.PCLI_ID) THEN RAISE cannot_change_counter; END IF; END IF; EXCEPTION WHEN cannot_change_counter THEN raise_application_error(-20000, 'Cannot Change Counter Value'); END; / the identity PCLI_ID is set by the trigger. In this case you may use the following mapping: <key-generator name="SEQUENCE" alias="PCV"> <param name="sequence" value="SEQ_{0}" /> <param name="returning" value="true" /> <param name="trigger" value="true" /> </key-generator> <class name="de.jsci.pcv.jdo.LieferantJDO" identity="id" key-generator="PCV"> <description>Lieferant</description> <cache-type type="count-limited" capacity="100"/> <map-to table="TAB_PCV_LIEFERANT" /> <field name="id" type="integer"> <sql name="PCLI_ID" type="numeric"/> </field> <field name="name" type="string"> <sql name="PCLI_NAME" type="char"/> </field> </class> You need to take care that castor replaces the {0} at keygenerator definition with the table name. If this does not work for you, you may have a look at our test cases. Of special interest for you are the classes: src/tests/ctf.jdo.tc2x.TestKeyGenSequence src/tests/ctf.jdo.tc2x.TestKeyGenReturning with mapping: src/tests/ctf/jdo/tc2x/mapping.xml and the script to setup the tables, sequences and so on: src/tests/jdo/oracle.sql I expect that you have read the documentation about keygeneration at: http://castor.codehaus.org/key-generator.html If all this does not help you should send me a script to setup your table at my maschine and also a testcase so that I can reproduce your problem at my side. Regards Ralf Shiva P. Kodityala schrieb: > > Could somebody help me tracing the sql statements generated by castor jdo? Do > I have to use Log4j? If so, how do I use Log4j with castor? Or any other > suggestions? I would like to look at trace info so that I can find out why I > am getting the exception. > > Thanks > > > -----Original Message----- > From: Shiva P. Kodityala [mailto:[EMAIL PROTECTED] > Sent: Wednesday, August 03, 2005 9:28 AM > To: [email protected] > Subject: RE: [castor-user] DuplicateIdentityException > > > Looked at that mapping.xml. > > I tried with this. > > <mapping> > > <key-generator name="SEQUENCE" > > > <param name="sequence" value="REAL_SEQUENCE_IN_ORACLEDB"/> > > </key-generator> > > > > > > > <class name="ClassName" identity="IDN" key-generator="SEQUENCE" > > <map-to table="REAL_TABLE_IN_ORACLEDB"/> > --- > --- > </class> > > </mapping> > > Tried to add trigger and returning param(s) also under key-generator. > > I am getting PrimaryKey violation error... > > Caused by: org.exolab.castor.jdo.PersistenceException: ORA-00001: unique > constra > int (PrimaryKey_Constraint) violated > > at org.exolab.castor.jdo.engine.SQLEngine.create(SQLEngine.java:709) > at org.exolab.castor.persist.ClassMolder.create(ClassMolder.java:916) > at org.exolab.castor.persist.LockEngine.create(LockEngine.java:489) > at > org.exolab.castor.persist.TransactionContext.create(TransactionContex > t.java:907) > at > org.exolab.castor.jdo.engine.DatabaseImpl.create(DatabaseImpl.java:37 > 4) > at > com.scif.app.policon.msg.TempPolicyConMessage.store(TempPolicyConMess > age.java:229) > > Does it mean that key-generator starts IDN value from 1 or something like > this? > > Thanks > > > -----Original Message----- > From: Werner Guttmann [mailto:[EMAIL PROTECTED] > Sent: Wednesday, August 03, 2005 12:14 AM > To: [email protected] > Subject: AW: [castor-user] DuplicateIdentityException > > > Shiva, > > as far as I can tell, this should be fine. Maybe somebody else with a more > solid Oracle background can reconfirm this. In addition, you could have a > look at the mapping file in src/tests/jdo, as it holds a couple of key > generator definitions as needed by the CTF test suite. > > Werner > > -----Ursprüngliche Nachricht----- > Von: Shiva P. Kodityala [mailto:[EMAIL PROTECTED] > Gesendet: Dienstag, 02. August 2005 19:15 > An: [email protected] > Betreff: RE: [castor-user] DuplicateIdentityException > > > Thanks for that link. I am using Oracle db. It looks like IDENTITY is not > for Oracle. I guess I should be using Sequence. > > > > Real Name of sequence in Oracle datbase is 'idnseq'. > > Does my mapping file look like this? > > <mapping ...> > > <key-generator name="SEQUENCE" alias="ALIASSEQ"> > <param name="sequence" value="idnseq"/> > </key-generator> > > <class name="ClassName" identity="IDN" key-generator="ALIASSEQ" > > <field name="IDN" type="integer" > > <sql name="IDN" type="integer"/> > </field> > --- > --- > -- > </class> > </mapping> > > Thanks > > > > > -----Original Message----- > From: Werner Guttmann [mailto:[EMAIL PROTECTED] > Sent: Tuesday, August 02, 2005 9:07 AM > To: [email protected] > Subject: AW: [castor-user] DuplicateIdentityException > > > Shiva, > > For such situations , please use the IDENTITY key-generator as explaind at > > http://castor.codehaus.org/key-generator.html > > Thanks > Werner > > > > -----Ursprüngliche Nachricht----- > Von: Shiva P. Kodityala [mailto:[EMAIL PROTECTED] > Gesendet: Dienstag, 02. August 2005 17:57 > An: [email protected] > Betreff: RE: [castor-user] DuplicateIdentityException > > >>From the Castor documentation, this Exception must not be thrown. > > In my mapping.xml: > > <class name="ClassName" identity="IDN" key-generator="MAX" > > > The value of column IDN is, in fact, is autogenerated. That means, if I put > the row through sqlplus client, in my insert statement, I do not need to have > any column 'IDN'. In that case, what should be key-generator? Do I have to > have this key-generator at all? > > Thanks > > > > > -----Original Message----- > From: Shiva P. Kodityala [mailto:[EMAIL PROTECTED] > Sent: Wednesday, June 29, 2005 11:36 AM > To: [email protected] > Subject: [castor-user] DuplicateIdentityException > > > I am getting this exception once in a while. If I understand it correctly, it > is possible in the application I am working in. > > Two processes process the (different) xml data and put to table > simultaneously. Table has primary key which is auto generated (so, not taken > from xml). Does DuplicateIdentityException mean that inserts are happening > simultaneously and getting the same autogenearted primary key (happening > before another's commit)? > > Fortunately, the application tries (certain number of times) again to insert > the same xml, in case of failure, and the insert succeeds. I don't know if it > is a good way. Pls advise. > > Thanks > > ------------------------------------------------- > If you wish to unsubscribe from this list, please > send an empty message to the following address: > > [EMAIL PROTECTED] > ------------------------------------------------- > > > ------------------------------------------------- > If you wish to unsubscribe from this list, please > send an empty message to the following address: > > [EMAIL PROTECTED] > ------------------------------------------------- > > > > ------------------------------------------------- > If you wish to unsubscribe from this list, please > send an empty message to the following address: > > [EMAIL PROTECTED] > ------------------------------------------------- > > > ------------------------------------------------- > If you wish to unsubscribe from this list, please > send an empty message to the following address: > > [EMAIL PROTECTED] > ------------------------------------------------- > > > > ------------------------------------------------- > If you wish to unsubscribe from this list, please > send an empty message to the following address: > > [EMAIL PROTECTED] > ------------------------------------------------- > > > ------------------------------------------------- > If you wish to unsubscribe from this list, please > send an empty message to the following address: > > [EMAIL PROTECTED] > ------------------------------------------------- > > > ------------------------------------------------- > If you wish to unsubscribe from this list, please > send an empty message to the following address: > > [EMAIL PROTECTED] > ------------------------------------------------- ------------------------------------------------- If you wish to unsubscribe from this list, please send an empty message to the following address: [EMAIL PROTECTED] ------------------------------------------------- ------------------------------------------------- If you wish to unsubscribe from this list, please send an empty message to the following address: [EMAIL PROTECTED] ------------------------------------------------- ------------------------------------------------- If you wish to unsubscribe from this list, please send an empty message to the following address: [EMAIL PROTECTED] -------------------------------------------------

