hi thomas,

by using a delete by query you bypass almost all of ojb's intelligence ;) a delete by query executes in your case a simple 'delete from person' without taking care of relationships and all that stuff.
to properly delete a collection of objecta you have to load them first and then delete each individually.


hth
jakob

Thomas Dudziak wrote:

When I delete objects that have collections (using indirection tables,
both 1:n or m:n) with deleteByQuery then it seems that the sub-objects are
not deleted even if I use a RemovalAwareCollection. Here is a test case
for MtoNTest that demonstrates this:

   public void testDeletePaper_RemovalAware()
   {
       ClassDescriptor cld = broker.getClassDescriptor(Paper.class);
       CollectionDescriptor cod =
cld.getCollectionDescriptorByName("qualifiers");
       Class collectionClass = cod.getCollectionClass();

cod.setCollectionClass(RemovalAwareCollection.class);

       try
       {
           Paper paper = createPaper();
           List qualifiers = paper.getQualifiers();
           Qualifier qual1 = (Qualifier) qualifiers.get(0);
           Qualifier qual2 = (Qualifier) qualifiers.get(1);
           Identity paperId = new Identity(paper, broker);

           broker.beginTransaction();
           broker.deleteByQuery(QueryFactory.newQuery(Paper.class,
(Criteria)null));
           broker.commitTransaction();

           broker.clearCache();
           broker.beginTransaction();

           Paper retPaper = (Paper) broker.getObjectByIdentity(paperId);
           assertNull(retPaper);

           Qualifier retQual1 =
(Qualifier) broker.getObjectByIdentity(new Identity(qual1, broker));
           Qualifier retQual2 =
(Qualifier) broker.getObjectByIdentity(new Identity(qual2, broker));

           assertNull(retQual1);
           assertNull(retQual2);

           broker.commitTransaction();
       }
       finally
       {
           cod.setCollectionClass(collectionClass);
       }
   }

Can somebody please confirm whether this is a bug or it is only me doing
something wrong ?

Tom



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






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



Reply via email to