We're updating the issue view to help you get more done. 

Subselect fetching is not used for collections if their entity owners are initialized in a batch

Description

An entity class is batch enabled and is using SUBSELECT fetch.

1 2 3 4 5 6 7 8 9 @Entity @BatchSize(size = 1000) public class EmployeeGroupSubselect { ... @OneToMany(cascade = CascadeType.ALL) @Fetch(FetchMode.SUBSELECT) private List<Employee> employees = new ArrayList<Employee>(); .... }

When loading a set of entities and their associations using ID based proxies created with em.getReference(...), rather than using subselect each assocation is loaded with an individual query like the below:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 select employees0_.EmployeeGroupSubselect_departmentName as Employee1_3_0_, employees0_.EmployeeGroupSubselect_groupName as Employee2_3_0_, employees0_.employees_id as employee3_3_0_, employee1_.id as id1_1_1_, employee1_.name as name2_1_1_ from EmployeeGroupSubselect_Employee employees0_ inner join Employee employee1_ on employees0_.employees_id=employee1_.id where employees0_.EmployeeGroupSubselect_departmentName=? and employees0_.EmployeeGroupSubselect_groupName=?

Environment

None

Status

Assignee

Gail Badner

Reporter

Stephen Fikes

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.1.0
5.0.9
4.2.21

Priority

Major