Skip to content

Commit 4f5832e

Browse files
committed
HHH-18859 fix error message for slice operator applied to non-string non-array
1 parent 0878fbb commit 4f5832e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@
193193
import org.hibernate.type.BasicType;
194194
import org.hibernate.type.descriptor.java.JavaType;
195195
import org.hibernate.type.descriptor.java.PrimitiveByteArrayJavaType;
196+
import org.hibernate.type.descriptor.java.StringJavaType;
196197
import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry;
197198
import org.hibernate.type.descriptor.java.spi.UnknownBasicJavaType;
198199
import org.hibernate.type.descriptor.jdbc.ObjectJdbcType;
@@ -5761,7 +5762,10 @@ else if ( ctx.simplePath() != null && ctx.slicedPathAccessFragment() != null ) {
57615762
final List<HqlParser.ExpressionContext> slicedFragments = ctx.slicedPathAccessFragment().expression();
57625763
final SqmTypedNode<?> lhs = (SqmTypedNode<?>) visitSimplePath( ctx.simplePath() );
57635764
final SqmExpressible<?> lhsExpressible = lhs.getExpressible();
5764-
if ( lhsExpressible != null && lhsExpressible.getSqmType() instanceof BasicPluralType<?, ?> ) {
5765+
if ( lhsExpressible == null ) {
5766+
throw new SemanticException( "Slice operator applied to expression of unknown type", query );
5767+
}
5768+
else if ( lhsExpressible.getSqmType() instanceof BasicPluralType<?, ?> ) {
57655769
return getFunctionDescriptor( "array_slice" ).generateSqmExpression(
57665770
List.of(
57675771
lhs,
@@ -5772,7 +5776,8 @@ else if ( ctx.simplePath() != null && ctx.slicedPathAccessFragment() != null ) {
57725776
creationContext.getQueryEngine()
57735777
);
57745778
}
5775-
else {
5779+
else if ( lhsExpressible.getRelationalJavaType() instanceof StringJavaType
5780+
&& !(lhs instanceof SqmPluralValuedSimplePath) ) {
57765781
final SqmExpression<?> start = (SqmExpression<?>) slicedFragments.get( 0 ).accept( this );
57775782
final SqmExpression<?> end = (SqmExpression<?>) slicedFragments.get( 1 ).accept( this );
57785783
return getFunctionDescriptor( "substring" ).generateSqmExpression(
@@ -5801,6 +5806,9 @@ else if ( ctx.simplePath() != null && ctx.slicedPathAccessFragment() != null ) {
58015806
creationContext.getQueryEngine()
58025807
);
58035808
}
5809+
else {
5810+
throw new SemanticException( "Slice operator applied to expression which is not a string or SQL array", query );
5811+
}
58045812
}
58055813
else {
58065814
throw new ParsingException( "Illegal domain path '" + ctx.getText() + "'" );

0 commit comments

Comments
 (0)