You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Thomas Dudziak <to...@first.gmd.de> on 2003/08/11 17:31:32 UTC
Bug with deleteByQuery and indirection tables ?
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: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Bug with deleteByQuery and indirection tables ?
Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi tom,
iterating is currently the only way.
jakob
Thomas Dudziak wrote:
>Then is there a OJB way to delete all rows in an indirection table
>at once (without having to iterate over all objects) ? All Query objects
>seem to require a class which I cannot supply when I want to delete from
>the indirection table, right ?
>
>Tom
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Bug with deleteByQuery and indirection tables ?
Posted by Thomas Dudziak <to...@first.gmd.de>.
Then is there a OJB way to delete all rows in an indirection table
at once (without having to iterate over all objects) ? All Query objects
seem to require a class which I cannot supply when I want to delete from
the indirection table, right ?
Tom
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Bug with deleteByQuery and indirection tables ?
Posted by Jakob Braeuchi <jb...@gmx.ch>.
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: ojb-user-unsubscribe@db.apache.org
>For additional commands, e-mail: ojb-user-help@db.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org