Return-Path: Delivered-To: apmail-db-torque-user-archive@www.apache.org Received: (qmail 40175 invoked from network); 21 Jan 2006 07:25:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Jan 2006 07:25:02 -0000 Received: (qmail 83846 invoked by uid 500); 21 Jan 2006 07:25:01 -0000 Delivered-To: apmail-db-torque-user-archive@db.apache.org Received: (qmail 83827 invoked by uid 500); 21 Jan 2006 07:25:00 -0000 Mailing-List: contact torque-user-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Apache Torque Users List" Reply-To: "Apache Torque Users List" Delivered-To: mailing list torque-user@db.apache.org Received: (qmail 83816 invoked by uid 99); 21 Jan 2006 07:25:00 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 20 Jan 2006 23:25:00 -0800 X-ASF-Spam-Status: No, hits=-10.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [209.237.227.194] (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 20 Jan 2006 23:24:58 -0800 Received: (qmail 40122 invoked by uid 1977); 21 Jan 2006 07:24:37 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 21 Jan 2006 07:24:37 -0000 Date: Fri, 20 Jan 2006 23:24:37 -0800 (PST) From: Thomas Fischer To: Apache Torque Users List Subject: AW: Joins in torque In-Reply-To: Message-ID: <20060120224858.D33311@minotaur.apache.org> References: MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="0-19172825-1137828277=:33311" X-Spam-Rating: localhost 1.6.2 0/1000/N X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N --0-19172825-1137828277=:33311 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi, I do not understand your problem. My guess is that the misunderstanding=20 arises a) because of Torque's silent db hits and caching the associated=20 objects and b) some peculiarities of the caching. Note: All this assumes you have standard generator settings (no=20 managers etc). regarding a) Assume you have the following code: (All this assumes you=20 have standard generator settings (no managers etc)). Criteria criteria =3D new Criteria(); List t12s =3D T12Peer.doSelect(criteria); T12 t12 =3D (T12) T12s.get(0); T1 t1 =3D t12.getT1(); // will query the db. t12.t1 was not read before. T1 othert1 =3D t12.getT1(); // Will not query db. t12.t1 Was read before. // (in fact, t1 =3D=3D othert1) And now using doSelectJoinXXX Criteria criteria =3D new Criteria(); List t12s =3D T12Peer.doSelectJoinT1(criteria); T12 t12 =3D (T12) T12s.get(0); T1 t1 =3D t12.getT1(); // will NOT query the db. t12.t1 was already read // by the doSelectJoin method And finally (to complete the confusion): Criteria criteria =3D new Criteria(); criteria.addJoin(T12Peer.T1_ID,T1Peer.T1_ID); List t12s =3D T12Peer.doSelect(criteria); T12 t12 =3D (T12) T12s.get(0); T1 t1 =3D t12.getT1(); // will query the db! explanation below. The first two examples should be clear because once you do T12.getT1()=20 the t1 result is cached in t12 and not read again. The DoSelectJoinXXX=20 method fills the t12.t1 objects by using a join. The last example is more difficult: If you use Criteria.addJoin(), the=20 join is NOT used to fill the associated objects (in this case t12.t1). The= =20 join can only be used to specify which t12's can be read. regarding b) Consider the following code: Criteria criteria =3D new Criteria(); List t12s =3D T12Peer.doSelect(criteria); T12 t12 =3D (T12) T12s.get(0); T1 t1 =3D t12.getT1(); List associatedT12s =3D t1.getT12s(); // will hit db! was not filled before Even if ((T12)associatedT12s.get(0)).equals(t12) would be true, in no case= =20 will ((T12)associatedT12s.get(0)) =3D=3D t12 will be true. Just because you= =20 fill one "direction" of association, this does not mean the other=20 "direction" is filled automatically. Read and debug the generated source=20 code of the methods T12.getT1() and t1.getT12s() for more information. I hope this shed some light on what is going on. Thomas On Fri, 20 Jan 2006, Stephan Spiegel wrote: > Hi, > > 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 resul= t > then just doing a doSelect and manually bring them together as done in th= e > following example: > > (Method in T12Peer): > > public static List bringThemTogether () throws TorqueException { > =09Criteria crit =3D new Criteria(); > =09List xx =3D doSelect(crit); > =09for (int i =3D 0; i < xx.size(); i++) { > =09=09T12 temp_obj1 =3D (T12)xx.get(i); > =09=09T1 temp_obj2 =3D (T1)temp_obj1.getT1(); > =09=09T2 temp_obj3 =3D (T2)temp_obj1.getT2(); > =09=09HashMap h =3D new HashMap(); > =09=09h.put("Table1",temp_obj2); > =09=09h.put("Table2",temp_obj3);} > =09=09xx.set(i,h); > =09} > =09return xx; > } > > using this I can directly access the relations between the values of T1 a= nd > T2. > > 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) > > Stephan > > -----Urspr=FCngliche 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 > > > > > > > Hi, > > 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 ti= me > you fetch a T2 Entry). > > 1b) do the same as in a1, but omit the T12.getT2s() step. Instead, get al= l > T2-Ids from all T12 you read in, do T2Peer.doSelect() with a criteria whe= re > all needed T2Ids are selected, and do the linking of the T2 objects to th= e > T12's manually. > > 2) look at the template code for generating the doSelectJoinXXX methods a= nd > 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, gath= er > 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. > > Thomas > > > "Stephan Spiegel" 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=B4s 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 > and >> T2 >> in SQL this would be: select T1.value, T2.value from T1, T2, T1_2 where >> T1.ID =3D T1_2.T1_ID and T2.ID =3D 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 > HowTo >> (doSelectJoin...) or in Criteria HowTo (crit.addJoin(...)) I always get > only >> 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 > mailing-list-archives, >> I can=B4t find a helpful message. Where is my mistake? Could somebody te= ll > me >> exactly how to add this join? >> >> (I=B4m using torque-3.2, MySQL 5, defaultidMethod=3Dnative) >> >> 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 > > --0-19172825-1137828277=:33311 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org For additional commands, e-mail: torque-user-help@db.apache.org --0-19172825-1137828277=:33311--