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); pmdQuery.andQualifier(valueExp); pmdQuery.addPrefetch("toPromotion") .setSemantics(PrefetchTreeNode.JOINT_PREFETCH_SEMANTICS); pmdQuery.addPrefetch("toPromotion.toPromotionOfferChain"); @SuppressWarnings("unchecked") 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? Tony ![]() |
- AddPrefetch Tony Giaccone
- Re: AddPrefetch Aristedes Maniatis
- Re: AddPrefetch Tony Giaccone

