IMHO auto-retrieve should be set to true only for table's reference (and not in every cases). So by default my preconisation is to set auto-retrieve to true in particulars cases well identified... For the prefetched relationships as far as I know there is some restrictions : - only works if your objects are in the cache. - it's not possible to retrieve instances farther than the first "layer" : for example to stay with the model I introduce in my previous post I can't directly prefetch listeC (a collection of C objects) from an instance of A. I need to do this : A result = (A)broker.getObjectByQuery(query);
broker.retrieveReference(result.getB(), "listeA"); broker.retrieveReference(result.getB(), "listeC"); And if I want to retrieve de D instance available on each C object I need the to add the following code : while (iter.hasNext()) { C c = (C)iter.next(); broker.retrieveReference(c, "d"); } I have the feeling that the use of the DeepRetrieve utility make the graph object retrieving easier ... Thanx for your feedback :-) JB -----Message d'origine----- De: Jakob Braeuchi A: OJB Users List Date: 29/11/2004 18:48 Objet: Re: Deep retrieve : a proposal hi jean-baptiste, ojb already offers auto-retrieve = true in the collection-descriptor to load related objects automatically. an additional feature are the prefetched relationships that allow you to load related object in a single query instead of executing one query for each parent object. what is the additional benefit of DeepRetrieve ? jakob CLARAMONTE Jean-Baptiste schrieb: > I've noticed that OJB doesn't offer a deep retrieve reference service, so I > have developped an utility for retrieving from one reference all the deep > references (and back references). > Example : > we have the following model : > [A]<(*)listeA-----(1)b>[B]<(1)b-----(*)listeC>[C]-----(1)d>[D] > /\ > (*)listeB > || > (*)listeE > \/ > [E] > > Supposing we already have retrieved a reference on [A] and now we would like > to retrieve all the references associated from this instance. Using the > DeepRerieve utility the following code will do the job for you : > > Criteria crit = new Criteria(); > crit.addEqualTo("idA", new Long(0)); > > QueryByCriteria query = QueryFactory.newQuery(A.class, crit); > > A result = (A)broker.getObjectByQuery(query); > > DeepRetrieve deepRetrieve = new DeepRetrieve(broker); > deepRetrieve.addRetrieveRef("b(listeA).listeC(b).d"); > deepRetrieve.addRetrieveRef("b.listeE(listeB)"); > deepRetrieve.retrieve(result); > > Without the DeepRetrieve utility the following code should have been used : > > Criteria crit = new Criteria(); > crit.addEqualTo("idA", new Long(0)); > > QueryByCriteria query = QueryFactory.newQuery(A.class, crit); > query.addPrefetchedRelationship("b"); > > A result = (A)broker.getObjectByQuery(query); > > broker.retrieveReference(result.getB(), "listeA"); > broker.retrieveReference(result.getB(), "listeC"); > Iterator iter = result.getB().getListeC().iterator(); > while (iter.hasNext()) { > C c = (C)iter.next(); > broker.retrieveReference(c, "d"); > broker.retrieveReference(c, "b"); > } > > broker.retrieveReference(result.getB(), "listeE"); > iter = result.getB().getListeE().iterator(); > while (iter.hasNext()) { > E e = (E)iter.next(); > broker.retrieveReference(e, "listeB"); > } > > >>From my first tests this DeepRetrive leads to the same amount of sql query. > The code is easier to read. (well from my point of view...) > > regards, > > JB > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] *** We scanned this email for malicious content *** *** IMPORTANT: Do not open attachments from unrecognized senders *** *** MailSystem ASTON *** --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]