You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (join.getAttribute().getName().equals(attribute)) {
returnjoin;
}
}
returnfrom.join(attribute, joinType);
}
This can result in in duplicate joins. Except for being inefficient, this also has problematic side effects.
In MySQL columns on which you want to order must be included in distinct queries.
In order to do a select distinct e from Entity e order by e.other.name you must join fetch e.other. In Specification terms this fetch join can be done with the predicate
return (root, query, builder) -> {
if (root.getJavaType().equals(query.getResultType())) {
// Only add the join fetch when the root is part of the entityroot.fetch(attribute, JoinType.INNER);
}
returnnull;
};
When the Orders are processed it creates another join (a non-fetch inner) which is used to perform the sorting on.
This results in a SQL query which MySQL does not accept.
JPQL created by Spring Data:
select distinct generatedAlias0
from Entity as generatedAlias0
inner joingeneratedAlias0.otheras generatedAlias2
inner join fetch generatedAlias0.otheras generatedAlias3
order bygeneratedAlias2.name
Hibernate produces a SQL query similar to:
select distinct generatedAlias0.*, generatedAlias3.*from Entity generatedAlias0
inner join Other generatedAlias2 ongeneratedAlias0.id=generatedAlias2.idinner join Other generatedAlias3 ongeneratedAlias0.id=generatedAlias3.idorder bygeneratedAlias2.name
It used to work with 2.4. I see that in #436 the logic in toExpressionRecursively was changed where it would check if it was already fetched, and thus not create a join.
spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java
Lines 762 to 771 in ee9ef86
This can result in in duplicate joins. Except for being inefficient, this also has problematic side effects.
In MySQL columns on which you want to order must be included in distinct queries.
In order to do a
select distinct e from Entity e order by e.other.name
you must join fetche.other
. In Specification terms this fetch join can be done with the predicateWhen the Orders are processed it creates another join (a non-fetch inner) which is used to perform the sorting on.
This results in a SQL query which MySQL does not accept.
JPQL created by Spring Data:
Hibernate produces a SQL query similar to:
It used to work with 2.4. I see that in #436 the logic in
toExpressionRecursively
was changed where it would check if it was already fetched, and thus not create a join.spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryUtils.java
Lines 641 to 649 in eb023fc
Note,
isAlreadyInnerJoined
does check the fetch joins.The text was updated successfully, but these errors were encountered: