openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Wisneski" <>
Subject question on OpenJPA FetchGroups
Date Thu, 21 Sep 2006 18:25:30 GMT
I am trying to use a FetchGroup to retrieve a path of relationships.

Can a fetchGroup be defined across multiple Entities?

My application has DeptBean, EmpBean, ProjectBean with a relationship
from DeptBean to EmpBean named "emps" and a relationship from EmpBean
to ProjectBean named "projects".  All relationship defined or
defaulted to LAZY.

When retrieving DeptBean, I want the related EmpBeans and in turn
their related ProjectBeans to be eagerly retrieved.

What I tried was

@FetchGroup (name="detail", attributes={
@FetchAttribute(name="emps" ,recursionDepth=2})
public class DeptBean{

Collection<EmpBean> emps

@FetchGroup   (name="detail", attributes = {
@FetchAttribute (name="tasks", recursionDepth=2)})
public class EmpBean {
Collection<ProjectBean> projects;

I then add "details" to the FetchPlan for the query

select d from DeptBean d where d.location='CA'

and maxFetchDepth was set to 4 in the persistence.xml

I find that the EmpBeans related via "emps"  are retrieved but not
"projects".   I could not find any way to go deeper than one level
using a FetchGroup.    The only way I  found to get "projects" to be
fetched on a query returning DeptBean was to define the relationships
as EAGER, but then this made the relationship EAGER all the time which
is not what I want.

View raw message