I am experiencing a problem when I try to store an object that contains a collection. It seems that I am only able to create and add one object to the collection at a time. Here are the details of my setup:

OJB cvs snapshot from yesterday (Aug 11)
WebSphere 4.0.5
DB2 7.2.6

The repository for the classes in question look like the following, with unnecessary details removed.


   <class-descriptor
          class="Child"
          table="SCHEMA.CHILD">
      <field-descriptor
         name="id"
         column="ID"
         jdbc-type="INTEGER"
         primarykey="true"
         autoincrement="true"
         access="readonly"
      />
      <field-descriptor
         name="parentId"
         column="PARENT_ID"
         jdbc-type="INTEGER"
      />
   </class-descriptor>

   <class-descriptor
          class="Parent"
          table="SCHEMA.PARENT">
      <field-descriptor
         name="id"
         column="ID"
         jdbc-type="INTEGER"
         primarykey="true"
         autoincrement="true"
         access="readonly"
      />
      <collection-descriptor
         name="children"
         auto-retrieve="true"
         auto-update="false"
         auto-delete="false"
         element-class-ref="Child">
         <inverse-foreignkey field-ref="parentId"/>
      </collection-descriptor>
   </class-descriptor>

I am using DB2 identity fields for the object IDs for both of these classes. Yes, I know this is not popular, but such is life. To support this I am using the SequenceManagerNativeImpl (modded to remove setReferenceFKs() as this does not seem to work properly).

My code looks like the following:

        // the parent has already been saved and has a valid ID
        Parent parent = someparent;

        Transaction transaction = odmg.currentTransaction();
        transaction.lock(parent, Transaction.WRITE);

        Child child1 = new Child();
        child1.setParentId(parent.getId());
        parent.addChild(child1);
        transaction.lock(child1, Transaction.WRITE);

        Child child2 = new Child();
        child2.setParentId(parent.getId());
        parent.addChild(child2);
        transaction.lock(child2, Transaction.WRITE);

After this I commit the transaction but only the first child is stored.

Any thoughts?

Thanks,

Mike




--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to