From c9c50d8afd0c1914e5eccc2270bcdd2960baddf5 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Mon, 12 Sep 2016 23:57:48 +0100 Subject: [PATCH] HHH-11081 - JPA join with treat causes QuerySyntaxException: Invalid path --- .../query/criteria/internal/FromImplementor.java | 4 ---- .../query/criteria/internal/QueryStructure.java | 12 +++++------- .../internal/path/CollectionAttributeJoin.java | 10 ---------- .../criteria/internal/path/ListAttributeJoin.java | 10 ---------- .../criteria/internal/path/MapAttributeJoin.java | 10 ---------- .../criteria/internal/path/SetAttributeJoin.java | 10 ---------- .../internal/path/SingularAttributeJoin.java | 10 ---------- 7 files changed, 5 insertions(+), 61 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/FromImplementor.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/FromImplementor.java index 26c580e7dc..0aefb558de 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/FromImplementor.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/FromImplementor.java @@ -22,8 +22,4 @@ public interface FromImplementor extends PathImplementor, From { FromImplementor correlateTo(CriteriaSubqueryImpl subquery); void prepareCorrelationDelegate(FromImplementor parent); FromImplementor getCorrelationParent(); - - default boolean shouldBeRendered(){ - return true; - } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/QueryStructure.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/QueryStructure.java index 16a097711b..df54e9c98f 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/QueryStructure.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/QueryStructure.java @@ -336,13 +336,11 @@ public class QueryStructure implements Serializable { } for ( Join join : joins ) { - if ( ((FromImplementor) join).shouldBeRendered() ) { - ((FromImplementor) join).prepareAlias( renderingContext ); - jpaqlQuery.append( renderJoinType( join.getJoinType() ) ) - .append( ((FromImplementor) join).renderTableExpression( renderingContext ) ); - renderJoins( jpaqlQuery, renderingContext, join.getJoins() ); - renderFetches( jpaqlQuery, renderingContext, join.getFetches() ); - } + ( (FromImplementor) join ).prepareAlias( renderingContext ); + jpaqlQuery.append( renderJoinType( join.getJoinType() ) ) + .append( ( (FromImplementor) join ).renderTableExpression( renderingContext ) ); + renderJoins( jpaqlQuery, renderingContext, join.getJoins() ); + renderFetches( jpaqlQuery, renderingContext, join.getFetches() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/CollectionAttributeJoin.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/CollectionAttributeJoin.java index b813f6c53c..bc8b08884e 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/CollectionAttributeJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/CollectionAttributeJoin.java @@ -119,16 +119,6 @@ public class CollectionAttributeJoin original.setAlias( alias ); } - @Override - public boolean shouldBeRendered() { - if ( getJoins().size() > 0 ) { - return true; - } - else { - return false; - } - } - @Override public String render(RenderingContext renderingContext) { return "treat(" + original.render( renderingContext ) + " as " + treatAsType.getName() + ")"; diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/ListAttributeJoin.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/ListAttributeJoin.java index 8ed333dbb0..cd9776c1f3 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/ListAttributeJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/ListAttributeJoin.java @@ -127,16 +127,6 @@ public class ListAttributeJoin original.setAlias( alias ); } - @Override - public boolean shouldBeRendered() { - if ( getJoins().size() > 0 ) { - return true; - } - else { - return false; - } - } - @Override public String render(RenderingContext renderingContext) { return "treat(" + original.render( renderingContext ) + " as " + treatAsType.getName() + ")"; diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/MapAttributeJoin.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/MapAttributeJoin.java index 2d4ff7c59a..2e9ac06eda 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/MapAttributeJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/MapAttributeJoin.java @@ -148,16 +148,6 @@ public class MapAttributeJoin original.setAlias( alias ); } - @Override - public boolean shouldBeRendered() { - if ( getJoins().size() > 0 ) { - return true; - } - else { - return false; - } - } - @Override public String render(RenderingContext renderingContext) { return "treat(" + original.render( renderingContext ) + " as " + treatAsType.getName() + ")"; diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/SetAttributeJoin.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/SetAttributeJoin.java index 04fcaa729a..bde16c85f6 100644 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/SetAttributeJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/SetAttributeJoin.java @@ -124,16 +124,6 @@ public class SetAttributeJoin original.setAlias( alias ); } - @Override - public boolean shouldBeRendered() { - if ( getJoins().size() > 0 ) { - return true; - } - else { - return false; - } - } - @Override public String render(RenderingContext renderingContext) { return "treat(" + original.render( renderingContext ) + " as " + treatAsType.getName() + ")"; diff --git a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/SingularAttributeJoin.java b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/SingularAttributeJoin.java index 8de9bd69d3..4cd9652fb1 100755 --- a/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/SingularAttributeJoin.java +++ b/hibernate-core/src/main/java/org/hibernate/query/criteria/internal/path/SingularAttributeJoin.java @@ -159,16 +159,6 @@ public class SingularAttributeJoin extends AbstractJoinImpl { return criteriaBuilder().getEntityManagerFactory().getMetamodel().managedType( treatAsType ); } - @Override - public boolean shouldBeRendered() { - if ( getJoins().size() > 0 ) { - return true; - } - else { - return false; - } - } - @Override public String render(RenderingContext renderingContext) { return "treat(" + original.render( renderingContext ) + " as " + treatAsType.getName() + ")";