Skip to content

Commit 3a1dabf

Browse files
committed
HHH-17002, HHH-18820, HHH-19391, HHH-18514 deal with anonymous CTE problem
- just deprecate the method, since HQL doesn't allow anonymous CTEs - perhaps we need to do the same for the withRescursiveXxxxx() methods - I don't really see a better fix, since nested CTEs can be composed before composing them with the outer query (perhaps we could modify the aliases of all CTEs after the whole query is built)
1 parent 5145400 commit 3a1dabf

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

hibernate-core/src/main/java/org/hibernate/query/criteria/JpaCteContainer.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ public interface JpaCteContainer extends JpaCriteriaNode {
3333
* which can be used for querying.
3434
*
3535
* @see JpaCriteriaQuery#from(JpaCteCriteria)
36+
*
37+
* @deprecated Use {@link #with(String, AbstractQuery)} and provide an explicit
38+
* name for the CTE
3639
*/
40+
@Deprecated(since = "7", forRemoval = true)
3741
<T> JpaCteCriteria<T> with(AbstractQuery<T> criteria);
3842

3943
/**

hibernate-core/src/main/java/org/hibernate/query/sqm/tree/AbstractSqmDmlStatement.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.hibernate.query.criteria.JpaRoot;
1111
import org.hibernate.query.sqm.NodeBuilder;
1212
import org.hibernate.query.sqm.SqmQuerySource;
13+
import org.hibernate.query.sqm.spi.SqmCreationHelper;
1314
import org.hibernate.query.sqm.tree.cte.SqmCteContainer;
1415
import org.hibernate.query.sqm.tree.cte.SqmCteStatement;
1516
import org.hibernate.query.sqm.tree.expression.SqmParameter;
@@ -91,9 +92,10 @@ public <X> JpaCteCriteria<X> getCteCriteria(String cteName) {
9192
return (JpaCteCriteria<X>) cteStatements.get( cteName );
9293
}
9394

94-
@Override
95+
@Override @Deprecated
9596
public <X> JpaCteCriteria<X> with(AbstractQuery<X> criteria) {
96-
return withInternal( generateAlias(), criteria );
97+
// Use of acquireUniqueAlias() results in interpretation cache miss
98+
return withInternal( "_" + SqmCreationHelper.acquireUniqueAlias(), criteria );
9799
}
98100

99101
@Override

hibernate-core/src/main/java/org/hibernate/query/sqm/tree/select/AbstractSqmSelectQuery.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.hibernate.query.criteria.JpaSelection;
2121
import org.hibernate.query.criteria.JpaSetReturningFunction;
2222
import org.hibernate.query.sqm.NodeBuilder;
23+
import org.hibernate.query.sqm.spi.SqmCreationHelper;
2324
import org.hibernate.query.sqm.tree.AbstractSqmNode;
2425
import org.hibernate.query.sqm.tree.SqmCopyContext;
2526
import org.hibernate.query.sqm.tree.SqmRenderContext;
@@ -121,9 +122,10 @@ public <X> JpaCteCriteria<X> getCteCriteria(String cteName) {
121122
return (JpaCteCriteria<X>) cteStatements.get( cteName );
122123
}
123124

124-
@Override
125+
@Override @Deprecated
125126
public <X> JpaCteCriteria<X> with(AbstractQuery<X> criteria) {
126-
return withInternal( generateAlias(), criteria );
127+
// Use of acquireUniqueAlias() results in interpretation cache miss
128+
return withInternal( "_" + SqmCreationHelper.acquireUniqueAlias(), criteria );
127129
}
128130

129131
@Override

0 commit comments

Comments
 (0)