You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Steven Rudolf <St...@web.de> on 2012/01/13 22:07:05 UTC
Fetch lazy modeled entities in multiple hierarchical levels with
criteria api
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?
Re: Fetch lazy modeled entities in multiple hierarchical levels
with criteria api
Posted by Pinaki Poddar <pp...@apache.org>.
Hi,
Please refer to documentation on OpenJPA FetchPlan [1].
[1]
http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_fetch
-----
Pinaki Poddar
Chair, Apache OpenJPA Project
--
View this message in context: http://openjpa.208410.n2.nabble.com/Fetch-lazy-modeled-entities-in-multiple-hierarchical-levels-with-criteria-api-tp7185675p7196640.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.