| Author |
JPA 2.0 Criteria, fetching whole entity graph
|
Darek Osiennik
Greenhorn
Joined: Apr 18, 2012
Posts: 3
|
|
Hi.
I have a entity class SysDic (application dictionary) with parent and childrens fields with annotation(Fetch = FetchType.Lazy). In my Ejb client bean I have a method dicGetFull. I would like to get full dictionary(whole graph) by using Criteria API so I have written following code:
But it is not working, only one level is fetched but I'm would like to fetch whole graph. It is possible using Criteria? How I can do it when my fields in entity definition are lazy?
Thanks for help
|
 |
Darek Osiennik
Greenhorn
Joined: Apr 18, 2012
Posts: 3
|
|
|
Anybody knows? It is important for me.
|
 |
Darek Osiennik
Greenhorn
Joined: Apr 18, 2012
Posts: 3
|
|
public SysDic getRoot() throws Throwable {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<SysDic> q = cb.createQuery(SysDic.class);
Root<SysDic> dic = q.from(SysDic.class);
q.select(dic).where(cb.equal(dic.get("kind"), SysConst.c_str_DIC_KIND_ROOT));
TypedQuery<SysDic> tq = entityManager.createQuery(q);
return tq.getSingleResult();
}
public SysDic getFull() throws Throwable {
CriteriaBuilder cb = entityManager.getCriteriaBuilder();
CriteriaQuery<SysDic> q = cb.createQuery(SysDic.class);
Root<SysDic> dic = q.from(SysDic.class);
q.distinct(true);
dic.fetch("childrens", JoinType.LEFT);
TypedQuery<SysDic> tq = entityManager.createQuery(q);
tq.getResultList();
SysDic root = getRoot();
return root;
}
Greetings , Darek
|
 |
 |
|
|
subject: JPA 2.0 Criteria, fetching whole entity graph
|
|
|