openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Steven Rudolf <Steven.Rud...@web.de>
Subject Fetch lazy modeled entities in multiple hierarchical levels with criteria api
Date Fri, 13 Jan 2012 21:07:05 GMT
Hello OpenJpa-Users!

I am using JPA2 with it's Criteria API to select my entities from the 
database. The implementation is OpenJPA on WebSphere Application Server 
(afaik version 2.1.1). All my entities are modeled with Fetchtype=Lazy.

I select an entity with some criteria from the database and want to load 
all nested data from sub-tables at once. If I have a datamodel where 
table A is joined oneToMany to table B, I can use a Fetch-clause in my 
criteria query:

|CriteriaBuilder  cb=  entityManager.getCriteriaBuilder();
CriteriaQuery<A>  cq=  cb.createQuery(A.class);
Root<A>  root=  cq.from(A.class);
Fetch<A,B>  fetch=  root.fetch(A_.elementsOfB,  JoinType.LEFT);
|

This works fine. I get an element A and all of its elements of B are 
filled correctly. Now table B has a oneToMany-relationship to table C 
and I want to load them too. So I add the following statement to my query:

|Fetch<B,C>  fetch2=  fetch.fetch(B_.elementsOfC,  JoinType.LEFT);
|

But this wont do anything.

Does anybody know how to fetch multi level entities in one query?


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message