openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jean-Baptiste BRIAUD -- Novlog <j-b.bri...@novlog.com>
Subject Dynamic fetch plan question
Date Wed, 29 Jul 2009 14:13:57 GMT
Hi,

I'm reading doc on fetch plan and fetch group (I discover that feature).
What I want to do is to dynamically specify the attribute (atomic or  
not) for a query in order to get back a List<A> with partial values  
rather than a List<Object[]>.
I feel it is possible reading the doc, but there are still some "black  
hole" in my mind.

Questions from the doc example :

OpenJPAEntityManager kem = OpenJPAPersistence.cast(em);
// Question 1 : does it mean that EntityManager was in fact an  
instance of OpenJPAEntityManager ?

kem.getFetchPlan().addField(Magazine.class, "publisher");
// Question 2 : OK, here it works because publisher is a "relational  
"attribute that was set to lazy with annotation.
// So that call make it eager dynamically but what about "non  
relational" @Basic attribute ? They can't be lazy or eager.
// So, how do I dynamically add/remove @Basic attributes from being  
retreive using fetch plan ? Is it possible ?
//
// Do you think I could (should ?) remove all fields from fetch plan  
and then add one by one so I won't have to deal with eager or lazy  
annotation ?

Magazine mag = em.find(Magazine.class, magId);
// Question 3 : will all that work with a query that get back several  
Magazine ?
// something like that for example :
             final String ql = "SELECT m FROM Magazine m";
             final Query query = em.createQuery(ql);
             final List<Magazine> requestResult = query.getResultList();


Mime
View raw message