CONTEXT:
I have a model (text UML): [A]<>-1---*-[B] [A]<>-1---*-[C] [C]-*-----*-[B] IMPLEMENTATION: In the mapping file, classes B and C "depends" on A. For the many-to-many association between B and C, the association table is mapped to the C_A_Assoc class (which doesn't "depends"). Class C then implements jdoAfterCreate() and attempts to create() the appropriate C_A_Assoc objects therein. When I do: A a = new A(); B b = new B(); a.addB(b); C c = new C() a.addC(c); c.addB(b); db.begin(); db.create(a); db.commit(); Everything persist fine. PROBLEM: However, if I do: A a = new A(); B b = new B(); a.addB(b); db.begin(); db.create(a); db.commit(); C c = new C() a.addC(c); c.addB(b); db.begin(); db.update(a); db.commit(); Or: A a = new A(); B b = new B(); a.addB(b); db.begin(); db.create(a); db.commit(); db.begin() a = (A) db.load(A.class, a.id); C c = new C() a.addC(c); c.addB(b); db.commit(); I get: org.exolab.castor.jdo.DuplicateIdentityException: Duplicate identity found for object of type test.C with identity 1: an object with the same identity already exists in persistent storage And, yes, I ran the update transaction code on a clean database. It seems Castor tries to reuse the identity of the association object create()d in jdoAfterCreate() or the identity of the C object just created. This happens if the object is created as a result of being added to a parent object that is updated, but not if the object is created during its parent's creation. In my "real" application, this pattern occurs often where a parent object has allowable values (which are children) and another child has references to some of these values. I've tried to implement this pattern other ways in Castor with no success. I really don't want to "hard-code" SQL for this. At this point, I'm open to any other suggestions. I've attached code, a mapping file, and SQL to create the tables. -doug
src.zip
Description: Binary data
