HHH-15452 Predicate add expression results in UnsupportedOperationException

This commit is contained in:
Andrea Boriero 2022-08-17 18:59:30 +02:00 committed by Andrea Boriero
parent 0945cae46d
commit beb7a37d02
5 changed files with 15 additions and 13 deletions

View File

@ -6,7 +6,7 @@
*/ */
package org.hibernate.query.sqm.tree.predicate; package org.hibernate.query.sqm.tree.predicate;
import java.util.Collections; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.NodeBuilder;
@ -33,7 +33,7 @@ public abstract class AbstractSqmPredicate extends AbstractSqmExpression<Boolean
@Override @Override
public List<Expression<Boolean>> getExpressions() { public List<Expression<Boolean>> getExpressions() {
/// most predicates do not have sub-predicates /// most predicates do not have sub-predicates
return Collections.emptyList(); return new ArrayList<>(0);
} }
} }

View File

@ -6,14 +6,13 @@
*/ */
package org.hibernate.query.sqm.tree.predicate; package org.hibernate.query.sqm.tree.predicate;
import java.util.Collections; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.tree.SqmCopyContext; import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.query.sqm.tree.expression.SqmExpression; import org.hibernate.query.sqm.tree.expression.SqmExpression;
import org.hibernate.sql.ast.tree.predicate.NegatedPredicate;
import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.Expression;
@ -73,7 +72,9 @@ public class SqmBooleanExpressionPredicate extends AbstractNegatableSqmPredicate
@Override @Override
public List<Expression<Boolean>> getExpressions() { public List<Expression<Boolean>> getExpressions() {
return Collections.singletonList( booleanExpression ); final List<Expression<Boolean>> expressions = new ArrayList<>( 1 );
expressions.add( booleanExpression );
return expressions;
} }
@Override @Override

View File

@ -6,7 +6,7 @@
*/ */
package org.hibernate.query.sqm.tree.predicate; package org.hibernate.query.sqm.tree.predicate;
import java.util.Collections; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.NodeBuilder;
@ -59,7 +59,9 @@ public class SqmGroupedPredicate extends AbstractSqmPredicate {
@Override @Override
public List<Expression<Boolean>> getExpressions() { public List<Expression<Boolean>> getExpressions() {
return Collections.singletonList( subPredicate ); final List<Expression<Boolean>> expressions = new ArrayList<>( 1 );
expressions.add( subPredicate );
return expressions;
} }
@Override @Override

View File

@ -11,9 +11,7 @@ import java.util.List;
import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.NodeBuilder;
import org.hibernate.query.sqm.SemanticQueryWalker; import org.hibernate.query.sqm.SemanticQueryWalker;
import org.hibernate.query.sqm.SqmExpressible;
import org.hibernate.query.sqm.tree.SqmCopyContext; import org.hibernate.query.sqm.tree.SqmCopyContext;
import org.hibernate.sql.ast.tree.predicate.Junction;
import jakarta.persistence.criteria.Expression; import jakarta.persistence.criteria.Expression;
@ -88,8 +86,7 @@ public class SqmJunctionPredicate extends AbstractSqmPredicate {
@Override @Override
public List<Expression<Boolean>> getExpressions() { public List<Expression<Boolean>> getExpressions() {
//noinspection unchecked return new ArrayList<>( predicates );
return (List<Expression<Boolean>>) (List<?>) predicates;
} }
@Override @Override

View File

@ -6,7 +6,7 @@
*/ */
package org.hibernate.query.sqm.tree.predicate; package org.hibernate.query.sqm.tree.predicate;
import java.util.Collections; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.hibernate.query.sqm.NodeBuilder; import org.hibernate.query.sqm.NodeBuilder;
@ -58,7 +58,9 @@ public class SqmNegatedPredicate extends AbstractNegatableSqmPredicate {
@Override @Override
public List<Expression<Boolean>> getExpressions() { public List<Expression<Boolean>> getExpressions() {
return Collections.singletonList( wrappedPredicate ); final List<Expression<Boolean>> expressions = new ArrayList<>( 1 );
expressions.add( wrappedPredicate );
return expressions;
} }
@Override @Override