cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Shea <>
Subject Using SQLTemplate to prefetch relationships.
Date Mon, 25 Aug 2008 18:50:21 GMT

I am attempting to use a SQLTemplate to execute a query and prefetch 
relationships. I have been unable, so far, to get any relationships that 
are one-to-many to be prefetched. Is there any further documentation 
about prefetching dependencies with SQLTemplate? So far, all I have seen 
is this:

This basically just indicates that SQLTemplate uses JOINT semantics to 
prefetch, which makes sense. Presumably, the query must manually 
retrieve all the desired relationships, and I should call 
template.addPrefetch(...) for every relationship I want retrieved?

How should I retrieve the actual properties of the relationship objects? 
So far, I have been using:

select ...
#result('granteeId' 'String' )

where granteeId is a property of an object related to the root object of 
the query.

However, I get back errors like this:

org.apache.cayenne.CayenneRuntimeException: [v.2.0.4 October 8 2007] 
Null value for 'granteeId'. Snapshot: 

granteeId=null, permissionType=null, isGrantable=null}, 
version=-9223372036854775793, replaces=-9223372036854775808]. Prefix: null
When I run the query myself, manually, I can see that the value of 
granteeId returned by the query isn't null.

I have also tried calling template.setFetchingDataRows( false ) and then 
calling context.objectsFromDataRows() on the result of executing the 
query, but so far that has just generated me one object per datarow (so 
if a root object has 4 related dependent objects, I end up getting back 
4 distinct root objects, rather than 1 root with 4 objects in the 
appropriate relationship).

Any suggestions? If this is unclear, please let me know and I will try 
to clarify =)

Oh, I am using version 2.0.4 of Cayenne.


Mike Shea.

View raw message