cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tony Giaccone <>
Subject AddPrefetch
Date Sun, 13 Oct 2013 13:05:35 GMT

I came across a rather odd situation and I hope someone can give me some insight into what
is going on here. 

 I have a model (diagram attached).  And I'm using this code:

   Expression nameExp = ExpressionFactory.matchExp("name",key);
   Expression valueExp = ExpressionFactory.matchExp("value",value); 
   SelectQuery pmdQuery = new SelectQuery(PromotionMetaData.class,nameExp);
   List<PromotionMetaData> pmdl  = ctx.performQuery(pmdQuery);
   List<UiOfferChain> ofcl = new ArrayList<UiOfferChain>();
   for(PromotionMetaData item: pmdl)
	Promotion promo = item.getToPromotion();
	if (promo != null)
		PromotionOfferChain poc = promo.getToPromotionOfferChain();

This example code originally didn't have the calls to addPrefetch and worked fine. However,
I know I'm going to iterate through these objects(600), and so I set the prefetch to get them
all so that I don't execute over 1200 fetches as I iterate.

 Once the calls where made to AddPrefetch then the code fails with a null pointer exception.

With the prefetch in place as I singled stepped through the code, I could see Cayenne making
the three fetches when the call was made to performQuery.

This line, always returned null. 

	Promotion promo = item.getToPromotion();

It wasn't till I added the join semantics that the prefetch worked and the relationships where
valid. My question is why?  I've never had to use join semantics to prefetch to work and I
wonder what it is about this configuration that requires them? 


View raw message