aspose file tools
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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Reply 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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: JPA 2.0 Criteria, fetching whole entity graph
 
Similar Threads
Hibernate Hell
Parent and subcollection fetching
How to create horizontal treetable
Issues with Cacade.Merge
Hibernate 3.3.1 - Delete doesn't work