1

I have a Servlets web app using Castor (version 1.1.2.1) mappings and JDO. When I try to create a new object that has a m:1 relation, I get a DuplicateIdentityException for the parent object.

org.exolab.castor.jdo.DuplicateIdentityException: Duplicate identity found for object of type Parent with identity <1(1)>: an object with the same identity already exists in persistent storage.

My Parent object is loaded in a filter and set in the request.

Filter

Database db = getDatabase():
db.begin();
request.setAttribute("parent", db.load(Parent.class, 1));
db.commit();
db.close();

Servlet

Parent parent = (Parent) request.getAttribute("parent");
Database db = getDatabase();
db.begin();
new Child();
child.setParent(parent);
db.create(child); <-- Exception here: DuplicateIdentityException
db.commit();
db.close();

getDatabase calls JDOManager.getDatabase();

Mapping file:

<class name="Parent" identity="id" key-generator="IDENTITY">
    <cache=type="fifo" />
    <field name="id" type="integer">
        <sql name="id" type="integer" />
    </field>
    <field name="child" type="Child" collection="arraylist">
        <sql many-key="parent_id" />
    </field>
</class>

<class name="Child" identity="id" key-generator="IDENTITY">
    <cache=type="fifo" />
    <field name="id" type="integer">
        <sql name="id" type="integer" />
    </field>
    <field name="parent" type="Parent">
        <sql name="parent_id" />
    </field>
</class>

How can a create the Child object with the correct relationship to Parent using Castor JDO?

CubeJockey
  • 2,209
  • 8
  • 24
  • 31
Preston S
  • 2,751
  • 24
  • 37
  • While we wait for your wiki edit to [castor-jdo] to be approved, I've added the [castor] tag for an increased audience. – CubeJockey Apr 11 '16 at 18:18

0 Answers0