Meaningless Drivel is fun!*
The moose likes EJB and other Java EE Technologies and the fly likes JPA 2.0 Criteria, fetching whole entity graph Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JPA 2.0 Criteria, fetching whole entity graph" Watch "JPA 2.0 Criteria, fetching whole entity graph" New topic
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JPA 2.0 Criteria, fetching whole entity graph
 
Similar Threads
Hibernate 3.3.1 - Delete doesn't work
How to create horizontal treetable
Issues with Cacade.Merge
Hibernate Hell
Parent and subcollection fetching