cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Emanuele Maiarelli <emanu...@mengozzi.com>
Subject Cayenne 3.0.2 rop and reflection.
Date Thu, 07 Jun 2012 22:07:42 GMT
  

I'm trying to move an application built around cayenne 2.0.4 to
3.0.2 and im facing an odd problem. 

I've some objects with 1 to n
relation, that calls to a generic method getTo...() via reflection, that
returns null, even if the underlaying database holds the correct
reference. 

So i tested the object calling the method without
reflection it works correcty. 

For instance: 

In this case 


ObjectContext newct=this.instance.getFreshContex(); // this methods
returns new CayenneContext(channel);
 SelectQuery sq=new
SelectQuery(Dochdrs.class);
 List  dd=newct.performQuery(sq);

this.instance.setupPrefetch(sq, Dochdrs.class,newct, 1);

 for (Dochdrs
doc:dd)
 {
 System.out.println(doc.getToCentrocosti().getCcDesc());
 }


setupPrefetch is coded that way: 

public void
setupPrefetch(SelectQuery q, Class queryClass,ObjectContext ctx,int
prefLvl) {
 EntityResolver resolver = ctx.getEntityResolver();

ObjEntity entity = resolver.lookupObjEntity(queryClass);

 Collection
c=entity.getRelationships();
 for (Object o:c)
 {
 ObjRelationship
rel=(ObjRelationship)o;
 if ((rel.isToMany() && (prefLvl==1)) ||
(rel.isToMany()==false))
 {

System.out.println("PREFETCH:"+rel.getName());

q.addPrefetch(rel.getName());
 }
 }

 } 

Now if i call
doc.getToCentrocosti().getCcDesc() i see cayenne fetching the related
object. 

If i call doc.getToCentrocosti() via reflection seems like
cayenne dosen't fetch the related object and simply return a null
reference 

and no further attempts to fetch the related object are
done. 

Everything works correctly under 2.0.4 where cayenne seems to
fetche all related objects during the execution of the SelectQuery.


Now tracking the issue on the application isnt so immediate, i wonder
if its a cayenne 3.0.2 that dosen't supports that 

kinds of calls via
reflection, or the problem lies somewhere in my code. 

Thanks in
advice, 

Emanuele 
-- 

  
Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message