Kumar,

Check for Exolab site for "keygen" ... there is one for Oracle, I believe it is called "SEQUENCE". They have them for major db's with auto-increment columns.

This will solve your problem !

Peter






From: "Kumar Dharm" <[EMAIL PROTECTED]>
Reply-To: [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Subject: [castor-dev] Castor Key generator
Date: Tue, 3 Dec 2002 21:15:17 -0800

Hi All,

Following is my mapping.xml file. I would like to use Oracle sequence for
inserting value into En_ID field.

<key-generator name="SEQUENCE" alias="seqgen">
<param name="sequence" value="{0}_SEQ"/>
</key-generator>
<class name="com.PCPgo.prm.web.encounter.EncounterJdo" identity="id">
<description>Encounter</description>
<map-to table="ENCOUNTER" xml="group" />
<field name="id" type="long" key-generator="seqgen">
<sql name="EN_ID" type="integer" />
<xml node="element" />
</field>
<field name="name" type="string" >
<sql name="EN_NAME" type="varchar" dirty="ignore"/>
<xml node="element"/>
</field>
</class>

Now, While creating EncounterJdo object, I am setting value as follows.

EncounterJdo encounterJdo= new EncounterJdo();
encounterJdo.setName("Allan");
if (db == null)
throw new InternalException("DB is null");
db.begin();
db.create(encounterJdo);
db.commit();
db.close();

but it inserts EN_ID =0 and NAME = "Allan" and now if I run again it throws
following error. It means it doesn't generate sequence

org.exolab.castor.jdo.DuplicateIdentityException: Duplicate identity found
for
object of type com.PCPgo.prm.web.encounter.EncounterJdo with identity 0:
an objec t with the same identity already exists in persistent storage

Hope for solution.

Best regards,
Kumar

-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev

_________________________________________________________________
MSN 8 with e-mail virus protection service: 2 months FREE* http://join.msn.com/?page=features/virus

----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev

Reply via email to