Subselect not used when batch loading by id in Hibernate
Issue
-
An entity class is batch enabled and is using SUBSELECT fetch.
@Entity @BatchSize(size = 1000) public class EmployeeGroupSubselect { ... @OneToMany(cascade = CascadeType.ALL) @Fetch(FetchMode.SUBSELECT) private List<Employee> employees = new ArrayList<Employee>(); .... } -
When fetching a set of entities and their associations, subselect is not used to fetch the associations.
-
For each entity, a separate query is issue to fetch the association
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
- Red Hat JBoss Enterprise Application Platform (EAP) 6
- Hibernate 4
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.