Hi,
when I want to retrieve an object from the database that has got a
many-to-many relationship to another object of the same type I get the
following exception:
org.exolab.castor.jdo.TransactionAbortedException: Nested error:
org.exolab.castor.jdo.PersistenceException: The identity of a data object
of type castortest.data.Entity, has been changed from 2 to 0 since it is
loaded/create/update.
This is the code I am executing:
//create test data
Entity child = new Entity(1, "CubanCigar");
Entity parent = new Entity(2, "Cigar");
//create link (method creates child-link as well)
child.addParentEntity(parent);
db.begin();
db.create(parent);
db.create(child);
db.commit();
//re-read data
db.begin();
Entity cigar = (Entity) db.load( Entity.class, new Integer( 2 ));
db.commit();
The corresponding Mapping file is:
<?xml version="1.0"?>
<mapping>
<description>TestMapping for EntityTest</description>
<class name="castortest.data.Entity" identity="id">
<map-to table="entity" xml="Entity"/>
<!-- id -->
<field name="id" type="integer">
<bind-xml name="identifier"/>
<sql name="id" type="integer"/>
</field>
<!-- name -->
<field name="name" type="string">
<sql name="name"/>
</field>
<!-- Vector parentEntities-->
<field name="parentEntities"
type="castortest.data.Entity" collection="vector">
<bind-xml name="Parent" node="element"/>
<!-- parent relationship -->
<sql many-table="entityparent_rel"
many-key="parentid" name="childid"/>
</field>
<!-- Vector childEntities-->
<field name="childEntities"
type="castortest.data.Entity" collection="vector">
<bind-xml name="Child" node="element"/>
<!-- child relationship -->
<sql many-table="entityparent_rel"
many-key="childid" name="parentid"/>
</field>
</class>
</mapping>
Does anybody know what I am doing wrong?
thanx
helmut
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-dev