This one time, at band camp, Helmut Meisel said:

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

Helmut,

I noticed that you're mapping an object of type Entity to an object
of type Entity. This is known as a self relation. Castor does not
provide the ability for self relations (i.e. relating two objects
of the same type).

I don't believe that this is the cause of the exception you're
getting, but I'm trying to save you some time. You might spend a
long time trying to chase down this exception only to find that
ultimately, Castor cannot provide what you're trying to do.

Bruce
--

perl -e 'print unpack("u30","<0G)U8V4\@4VYY9&5R\"F9E<G)E=\$\!F<FEI+F-O;0\`\`");'

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

Reply via email to