On Mar 6, 2005, at 1:21 PM, tnaki..ofthome.net wrote:
> I retrieve an object obj using DataObjectUtils.ObjectForPK().
> I retrieve a list using obj.getOtherObjectArray(). This is fine.
> The problem is that an attribute I need isn't available in otherObject
> but rather in thirdObject.
> The problem is that for each otherObject i have to do a
> thirdObject = DataObjectUtils.ObjectForPK(context,
> ThirdObject.class, idMap)
> where idMap contains otherObjectID and a fourthObjectID (it's a n-to-n
> relation).
>
> I would like to prefetch a part of the relation represented by
> thirdObject, but since I'm using not SelectQueries to get the data, I
> don't have any idea how to the objects I need.
> I could always create a view in the database and that's all fine and
> well, but I'm interested in cayenne's caching possibilities so I'd be
> grateful for any info you throw at me. :)
Well, if you need a prefetch to optimize DB access, go back to
SelectQuery with prefetches instead of DataObjectUtils. Here is a
mechanism similar to DataObjectUtils internal working... but with
prefetches:
Expression qualifier = ExpressionFactory.matchAllDbExp(idMap,
Expression.EQUAL_TO);
SelectQuery query = new SelectQuery(MyClass.class, qualifier);
query.addPrefetch("rel1");
query.addPrefetch("rel2.rel3");
// ... etc...
Andrus
This archive was generated by hypermail 2.0.0 : Sun Mar 06 2005 - 19:58:55 EST