Fix rendering nested entity joins in pre Hibernate 5.1 emulation code
@@ -926,6 +926,30 @@ public class JoinManager extends AbstractManager<ExpressionModifier> {
}
}
if (!rootNode.getEntityJoinNodes().isEmpty()) {
+ if (tempSb == null) {
+ tempSb = new StringBuilder();
+ } else {
+ tempSb.setLength(0);
+ }
+ valuesNode = applyEntityJoins(sb, tempSb, clauseExclusions, aliasPrefix, rootNode, collectCollectionJoinNodes, renderFetches, ignoreCardinality, nodesToFetch, whereConjuncts, valuesNode, alwaysIncludedNodes, externalRepresentation);
+ }
+
+ if (valuesNode != null) {
+ if (noJoinValuesNodesSb.length() != 0) {
+ noJoinValuesNodesSb.append(" AND ");
+ }
+ renderValuesClausePredicate(noJoinValuesNodesSb, valuesNode, valuesNode.getAlias(), externalRepresentation);
+ }
+ }
+
+ if (noJoinValuesNodesSb.length() != 0) {
+ whereConjuncts.add(0, noJoinValuesNodesSb.toString());
+ }
+
+ return collectionJoinNodes;
+ }
+
+ private JoinNode applyEntityJoins(StringBuilder sb, StringBuilder tempSb, Set<ClauseType> clauseExclusions, String aliasPrefix, JoinNode rootNode, boolean collectCollectionJoinNodes, boolean renderFetches, boolean ignoreCardinality, Set<JoinNode> nodesToFetch, List<String> whereConjuncts, JoinNode valuesNode, Set<JoinNode> alwaysIncludedNodes, boolean externalRepresentation) {
// TODO: Fix this with #216
boolean isCollection = true;
if (mainQuery.jpaProvider.supportsEntityJoin() && !emulateJoins) {
@@ -960,11 +984,7 @@ public class JoinManager extends AbstractManager<ExpressionModifier> {
entityNode.registerDependencies();
if (entityNode.getOnPredicate() != null && !entityNode.getOnPredicate().getChildren().isEmpty()) {
- if (tempSb == null) {
- tempSb = new StringBuilder();
- } else {
tempSb.setLength(0);
- }
if (valuesNode != null) {
renderValuesClausePredicate(tempSb, valuesNode, valuesNode.getAlias(), externalRepresentation);
@@ -988,23 +1008,12 @@ public class JoinManager extends AbstractManager<ExpressionModifier> {
for (JoinNode treatedNode : entityNode.getTreatedJoinNodes().values()) {
valuesNode = applyJoins(sb, treatedNode.getAliasInfo(), treatedNode.getNodes(), clauseExclusions, aliasPrefix, collectCollectionJoinNodes, renderFetches, ignoreCardinality, nodesToFetch, whereConjuncts, valuesNode, alwaysIncludedNodes, externalRepresentation);
}
+ if (!entityNode.getEntityJoinNodes().isEmpty()) {
+ valuesNode = applyEntityJoins(sb, tempSb, clauseExclusions, aliasPrefix, entityNode, collectCollectionJoinNodes, renderFetches, ignoreCardinality, nodesToFetch, whereConjuncts, valuesNode, alwaysIncludedNodes, externalRepresentation);
}
}
}
-
- if (valuesNode != null) {
- if (noJoinValuesNodesSb.length() != 0) {
- noJoinValuesNodesSb.append(" AND ");
- }
- renderValuesClausePredicate(noJoinValuesNodesSb, valuesNode, valuesNode.getAlias(), externalRepresentation);
- }
- }
-
- if (noJoinValuesNodesSb.length() != 0) {
- whereConjuncts.add(0, noJoinValuesNodesSb.toString());
- }
-
- return collectionJoinNodes;
+ return valuesNode;
}
void renderValuesClausePredicate(StringBuilder sb, JoinNode rootNode, String alias, boolean externalRepresentation) {
