Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Meaning of FetchGroup#setShouldLoadAll(true)

Sorry for asking silly questions. Please have a look at this bug-report:
https://bugs.eclipse.org/325684

-- Frank



Frank Schwarz wrote:
> 
> Hi,
> 
> I've been investigating the new fetch-group feature(s) of EL 2.1.0 and
> there is something I'd like to understand:
> 
> Lets say you have got "Employee" -- "Project" (many to many)
> 
> FetchGroup projectGroup = new FetchGroup();
> projectGroup.addAttribute("name");
> 
> FetchGroup employeeGroup = new FetchGroup();
> employeeGroup.addAttribute("id");
> employeeGroup.addAttribute("name");
> employeeGroup.addAttribute("projects", projectGroup);
> 
> TypedQuery<Employee> query = em.createQuery("select e from ...",
> Employee.class);
> query.setHint(QueryHints.FETCH_GROUP, employeeGroup);
> query.setHint(QueryHints.BATCH, "e.projects");
> 
> List<Employee> emps = query.getResultList(); // (1)
> for (Employee e : emps) {
>   e.getProjekte().size(); // (2)
> }
> 
> You can observe two sql statements. This first one at position (1) to load
> all employees and the second one at position (2) to load all projects of
> all previously loaded employees.
> 
> I would have expected the second sql statement to occur also at position
> (1). I thought that this fetch plan was saying: Please ensure that all
> employees and all their projects are loaded when you return from
> "getResultList() and load all projects with a separate batch statement."
> 
> Would the following statement change the behavior to the one I am
> expecting?:
> 
> employeeGroup.setShouldLoadAll(true);
> 
> And, is batch fetching compatible with this setting?
> 
> 
> Thank you for your help,
> Frank
> 
> 
> PS: It is currently not possible to simply test it, as it will raise a NPE
> at
> org.eclipse.persistence.internal.sessions.AbstractSession$1.iterate(AbstractSession.java:4067)
> 
> 

-- 
View this message in context: http://old.nabble.com/Meaning-of-FetchGroup-setShouldLoadAll%28true%29-tp29738806p29747666.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top