If you add a fetch join for a singular atttibute after a regular join with the same path, the fetch join will be ignored.
{code:borderStyle=solid} @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; } {code} This query will fail, because the fetch join for 'm2' is not added to the sql query select clause.
{noformat} 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; {noformat} You can fix this by adding the following code to the method 'org.hibernate.hql.internal.ast.tree.DotNode.dereferenceEntityJoin(...)' at line 516: {code} ... } else { // NOTE : addDuplicateAlias() already performs nullness checks on the alias. currentFromClause.addDuplicateAlias(classAlias, elem); *elem.setFetch(elem.isFetch() || fetch);* } ... {code}
|