Forums Register Login

JPA 2.0 Criteria, fetching whole entity graph

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Anybody knows? It is important for me.
+Pie Number of slices to send: Send
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
Don't touch me. And dont' touch this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2680 times.
Similar Threads
Issues with Cacade.Merge
Parent and subcollection fetching
Hibernate 3.3.1 - Delete doesn't work
How to create horizontal treetable
Hibernate Hell
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:21:44.