Hi,
I hope you can me solving a problem with castor.:
I have 2 Classes A and B where B depends on A. If I insert a new Object A the first time(incl. depended Object B) everything is alright. The Object seems to be persistent, because it is in the MySQL-Database.
But if I want to insert a second Object A, I always get an Exception:
org.exolab.castor.jdo.DuplicateIdentityException: Duplicate identity found for object of type Abhaengig with identity 28: an object with the same identity already exists in persistent storage
But the new Object, which has to be inserted has the Value 29. The previous object (which I stored the first time) has the value 28.
It seems to me, that castor wants to store this object again, incl. the new object. Does it mean, that the first object is already in the same transaction and transient? How could it be, that the first object is persistent and transient? Please can you tell me what I am doing wrong?
a part of my Java-Code:
SQLAccess(){
sema = new Semaphore(1);
jdo = new JDO();
System.out.println("Database-Name: test");
jdo.setDatabaseName( "test" );
System.out.println("Config-File: database.xml");
jdo.setConfiguration( "database.xml" );
jdo.setClassLoader(getClass().getClassLoader());
try{
//Obtain a new database
System.out.println("trying to open database");
db = jdo.getDatabase();
System.out.println("Database opened");
...
}
boolean setBenutzer(Benutzer benutzer){try {
sema.p();
db.begin();
String query="select o from Benutzer o WHERE regid="+benutzer.getRegid();
System.out.println("Begin transaction");
Query oql;
QueryResults results=null;
System.out.print("OQL> ");
System.out.println("\""+query+"\"");
oql=db.getOQLQuery(query);
System.out.println("execute");
results=oql.execute();
System.out.println("done");
if (!results.hasMore()) {
System.out.println("Create Benutzer");
db.create(benutzer);
System.out.println("Created");
db.commit();
sema.v();
}
return true;
.....
}
/*
boolean setBenutzer(Benutzer benutzer){
try {
sema.p();
db.begin(); System.out.println("Create Benutzer");
db.create(benutzer);
System.out.println("Created");
db.commit();
sema.v();
return true;} ..... } */
I just call 2 times setBenutzer with different Benutzer Objects and get the Exception above. I tried it with both setBenutzer functions.
If I search for Benutzer objects by making a select, the new inserted Benutzer Object also returns.
(If I don't use the depend-relation and insert an Benutzer-Object, no error occures.)
a part of my mapping file:
<class name="Benutzer" identity="regid"> <cache-type type="none"/> <map-to table="benutzer" xml="Benutzer"/> <field name="regid" type="integer"> <sql name="regid" type="integer"/> <bind-xml name="regid" type="integer" node="attribute"/> </field> <field name="name" type="java.lang.String"> <sql name="name" type="varchar"/> <bind-xml name="name" type="java.lang.String" node="element"/> </field>
<!--- 1:n Relation mit Tabelle Abhaengig (Abhaengig depends on Benutzer)-->
<field name="abhaengig" type="Abhaengig" required="true" collection="vector">
<sql many-key="userid"/>
<bind-xml name="abhaengig" node="element"/>
</field>
......
</class>
<class name="Abhaengig" identity="regid" depends="Benutzer"> <cache-type type="none"/> <map-to table="abhaengig" xml="Abhaengig"/>
<field name="regid" type="integer"> <sql name="regid" type="integer"/> <bind-xml node="attribute"/> </field>
<field name="benutzer" type="Benutzer"> <sql name="userid"/> <bind-xml name="benutzer" node="element" reference="true"/> </field>
<field name="komisch" type="java.lang.String"> <sql name="komisch" type="varchar"/> <bind-xml name="komisch" type="java.lang.String" node="element"/> </field> </class>
I hope you can help me solving my problem and tell me what I am doing wrong.
Thank you in advance Fabian Wolff
----------------------------------------------------------- If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user
