193193import org .hibernate .type .BasicType ;
194194import org .hibernate .type .descriptor .java .JavaType ;
195195import org .hibernate .type .descriptor .java .PrimitiveByteArrayJavaType ;
196+ import org .hibernate .type .descriptor .java .StringJavaType ;
196197import org .hibernate .type .descriptor .java .spi .JavaTypeRegistry ;
197198import org .hibernate .type .descriptor .java .spi .UnknownBasicJavaType ;
198199import 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