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

Fetch join is ignored

Description

If you add a fetch join for a singular atttibute after a regular join with the same path, the fetch join will be ignored.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 @Entity public class Address { @Id long id; @Basic String city; @Basic String street; } @Entity public class Person { @Id long id; @Basic String firstName; @Basic String lastName; @ManyToOne Address address; } @Entity public class Company { @Id long id; @Basic String name; @Basic String location; @ManyToOne Person manager; }

This query will fail, because the fetch join for 'm2' is not added to the sql query select clause.

1 2 3 4 5 6 select c from Company c inner join c.manager as m1 left join fetch c.manager as m2 left join fetch m2.address as a2 where m1.name like :param;

You can fix this by adding the following code to the method 'org.hibernate.hql.internal.ast.tree.DotNode.dereferenceEntityJoin(...)' at line 516:

1 2 3 4 5 6 7 ... } else { // NOTE : addDuplicateAlias() already performs nullness checks on the alias. currentFromClause.addDuplicateAlias(classAlias, elem); *elem.setFetch(elem.isFetch() || fetch);* } ...

Environment

None

Status

Assignee

Gail Badner

Reporter

Raimar Brauch

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

4.3.8

Priority

Major