db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Fischer <fisc...@seitenbau.net>
Subject RE: Joined Delete
Date Thu, 10 Apr 2008 07:32:38 GMT
Two things come to my mind

- A criteria can be changed when a select is made. You use the same
criteria to count and to delete. This is typically not a good idea.
- Unfortunately, select and delete sql is composed differently. Have you
tried to debug the sql code which is used for the delete ?

   Thomas

"Manaster, Carl" <CarlM@ACTIVX.com> schrieb am 09.04.2008 21:58:31:

> Hi, all,
>
> Below my signature is a test that demonstrates the problem I'm seeing.
> We're using torque 3.3.  When I try to delete through a join, it is
> deleting all records from the table, instead of just the records of
> interest.  It does not matter whether records in the T1 table exist or
> not.  Can you please explain this behavior and suggest a workaround?
> Thanks!
>
> Peace,
> --Carl
>
> package com.activx.apps.ms.quan.util.tests;
>
> import org.apache.torque.TorqueException;
> import org.apache.torque.util.CountHelper;
> import org.apache.torque.util.Criteria;
>
> import com.activx.lims.tests.TorqueTestCase;
> import com.activx.om.T1Peer;
> import com.activx.om.T2;
> import com.activx.om.T2Peer;
>
> /**
>  * create table t1 (t1_id bigint(20) not null auto_increment, primary
> key (t1_id));
>  * create table t2 (t2_id bigint(20) not null auto_increment, t1_id
> bigint(20) not null, primary key (t2_id));
>  */
> public class JoinedDeleteTest extends TorqueTestCase {
>
>    public void testDelete() throws Exception {
>       // start with an empty table
>       T2Peer.doDelete(new Criteria());
>       assertEquals(0, countT2s());
>
>       // add one record with a foreign key of 50
>       T2 t2 = new T2();
>       t2.setT1Id(50);
>       t2.save();
>
>       // see that the record made it in
>       assertEquals(1, countT2s());
>
>       // delete records joined to the #100 record (of which
> none exist)
>       final Criteria criteria = new
> Criteria().add(T1Peer.T1_ID, 100).addJoin(T1Peer.T1_ID, T2Peer.T1_ID);
>       assertEquals(0, new CountHelper().count(criteria));
>       T2Peer.doDelete(criteria);
>
>       // expect that no records were deleted, but in fact all
> records were deleted.
>       assertEquals(1, countT2s());
>    }
>
>    private int countT2s() throws TorqueException {
>       return new CountHelper().count(new
> Criteria().add(T2Peer.T2_ID, 0, Criteria.GREATER_EQUAL));
>    }
>
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
> For additional commands, e-mail: torque-user-help@db.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org


Mime
View raw message