db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stephan Spiegel" <spie...@szwo.de>
Subject AW: Joins in torque
Date Fri, 20 Jan 2006 22:12:18 GMT

first thanks for the fast and good response.

The doSelectJoinXXX methods are in the BaseT12Peer because here are the
foreign keys pointing to T1 and T2, so I could/can do T12.doSelectJoinT1()
and T12.doSelectJoinT2(). The point is, that I do not get any other result
then just doing a doSelect and manually bring them together as done in the
following example:

(Method in T12Peer):

public static List bringThemTogether () throws TorqueException {
	Criteria crit = new Criteria();
	List xx = doSelect(crit);
	for (int i = 0; i < xx.size(); i++) {
		T12 temp_obj1 = (T12)xx.get(i);
		T1 temp_obj2 = (T1)temp_obj1.getT1();
		T2 temp_obj3 = (T2)temp_obj1.getT2();
		HashMap h = new HashMap();
	return xx;

using this I can directly access the relations between the values of T1 and

I can't really see an effect using the doSelectJoin methods, but may be I'm
totally blind in the moment. Or does the above method hundreds of selects?
(I will have a look for the log4j as mentioned of Greg)


-----Ursprüngliche Nachricht-----
Von: Thomas Fischer [mailto:fischer@seitenbau.net]
Gesendet: Donnerstag, 19. Januar 2006 17:57
An: Apache Torque Users List
Betreff: RE: Joins in torque


There is no built-in support at the moment to get more than one level of
indrection read in at once.
As far as I can see, you have 3 1/2 possibilities:

1a) read the values one after another. Assuming you have defined foreign
keys (I'm not sure whether they should defined in T1 and T2 or in T12, on
this depends whether the doSelectJoinXXX methods are generated in T1Peer
and T2Peer or in T12Peer), do T1Peer.doSelectJoinT12(). For each T1Entry
you get, fetch the corresponding T12 Entry (this is already read from the
database) and then do T12.getT2s() (this will access the database each time
you fetch a T2 Entry).

1b) do the same as in a1, but omit the T12.getT2s() step. Instead, get all
T2-Ids from all T12 you read in, do T2Peer.doSelect() with a criteria where
all needed T2Ids are selected, and do the linking of the T2 objects to the
T12's manually.

2) look at the template code for generating the doSelectJoinXXX methods and
extend them for two levels of indirection.

3) A time ago, someone proposed a class which can read a whole tree of
objects at once. It can be found in scarab (somewhere around TRQS260). It
is rather reflection-centric and I do not have an idea whether it works
with Torque 3.2, but maybe that is what you want.

Personally, I use a modified method 1b). I would read all T1 I want, gather
the collection of T1 ids to read the associated T12's and link them
manually to the T1's. Then I'd use the T2 ids from there to read the T2's,
and link them manually to the T12's. This is rather fast (one select per
level of indirection, no object is transferred twice) and quite easy to
implement. You might have to override the initCollXXX() methods for the
used collections to make them public.


"Stephan Spiegel" <spiegel@szwo.de> schrieb am 19.01.2006 17:17:29:

> Hi, (in case this message is double please excuse me)
> I really do not understand what to do, I do not get the expected results!
> Let´s say I have 3 Tables: T1, T2 and T1_2
> T1:
> ID (integer pk)
> value (varchar)
> ...
> T2:
> ID (integer pk)
> value (varchar)
> ...
> T1_2:
> T1_ID (integer fk->T1)
> T2_ID (integer fk->T2)
> As a result, I would like to have a union table showing the values of T1
> T2
> in SQL this would be: select T1.value, T2.value from T1, T2, T1_2 where
> T1.ID = T1_2.T1_ID and T2.ID = T1_2.T2_ID
> if I get more than this (select * ...) would be fine as well.
> So, I have my classes but when I try to use them as written in Peers
> (doSelectJoin...) or in Criteria HowTo (crit.addJoin(...)) I always get
> the values of the T1_2-table
> As a first step, I try just to get the first half (result should show:
> T1.value, T1_2.T2_ID)
> so it should correspond to:
> doSelectJoinT1(crit) in T1_2Peer
> or:
> crit.addJoin(T1.ID,T1_2.T1_ID,Criteria.LEFT_JOIN)
> as a result I just get the T1_2 values. I checked the
> I can´t find a helpful message. Where is my mistake? Could somebody tell
> exactly how to add this join?
> (I´m using torque-3.2, MySQL 5, defaultidMethod=native)
> thanks in advance, Stephan
> ---------------------------------------------------------------------
> 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

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

View raw message