db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Manaster, Carl" <Ca...@ACTIVX.com>
Subject Joined Delete
Date Wed, 09 Apr 2008 19:58:31 GMT
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


Mime
View raw message