On Jul 29, 2009, at 16:13 , Jean-Baptiste BRIAUD -- Novlog wrote:
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 ?
Still not sure about that, look like not needed as I trace fetch plan
contain nothing defined eager with 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();
That is really so po-wer-full : it works also on request and it solve
entierly the problem !