hibernate/hibernate-orm · error · SemanticException
Slice operator applied to expression of unknown type
Error message
Slice operator applied to expression of unknown type
What it means
Thrown when applying the slice operator (e.g. x[1:3]) to an expression whose SQM type could not be determined; without a known type the translator cannot decide between string substring and SQL array slicing.
Solutions
- The slice operator was applied to an expression whose type cannot be determined. Give the expression a resolvable type (e.g. cast it or reference a typed path) before slicing.
Defensive patterns
Strategy: validation
When it happens
Trigger: The slice operator is applied to an unsupported expression: Slice operator applied to expression of unknown type
Common situations: Using array/string slicing on expressions whose type is unknown or neither string nor SQL array.
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/3d5a2ee0730fe4f5.
Report an issue: GitHub.
Appendix: source
Thrown at hibernate-core/src/main/java/org/hibernate/query/hql/internal/SemanticQueryBuilder.java:5780
public SemanticPathPart visitSyntacticDomainPath(HqlParser.SyntacticDomainPathContext ctx) {
if ( ctx.treatedNavigablePath() != null ) {
return visitTreatedNavigablePath( ctx.treatedNavigablePath() );
}
else if ( ctx.collectionValueNavigablePath() != null ) {
return visitCollectionValueNavigablePath( ctx.collectionValueNavigablePath() );
}
else if ( ctx.mapKeyNavigablePath() != null ) {
return visitMapKeyNavigablePath( ctx.mapKeyNavigablePath() );
}
else if ( ctx.simplePath() != null && ctx.indexedPathAccessFragment() != null ) {
return visitIndexedPathAccessFragment( visitSimplePath( ctx.simplePath() ), ctx.indexedPathAccessFragment() );
}
else if ( ctx.simplePath() != null && ctx.slicedPathAccessFragment() != null ) {
final var slicedFragments = ctx.slicedPathAccessFragment().expression();
final var lhs = (SqmTypedNode<?>) visitSimplePath( ctx.simplePath() );
final var lhsExpressible = lhs.getExpressible();
if ( lhsExpressible == null ) {
throw new SemanticException( "Slice operator applied to expression of unknown type", query );
}
else if ( lhsExpressible.getSqmType() instanceof BasicPluralType<?, ?> ) {
return getFunctionDescriptor( "array_slice" ).generateSqmExpression(
List.of(
lhs,
(SqmTypedNode<?>) slicedFragments.get( 0 ).accept( this ),
(SqmTypedNode<?>) slicedFragments.get( 1 ).accept( this )
),
null,
queryEngine()
);
}
else if ( lhsExpressible.getRelationalJavaType() instanceof StringJavaType
&& !(lhs instanceof SqmPluralValuedSimplePath) ) {
final var start = (SqmExpression<?>) slicedFragments.get( 0 ).accept( this );
final var end = (SqmExpression<?>) slicedFragments.get( 1 ).accept( this );
return getFunctionDescriptor( "substring" ).generateSqmExpression(
List.of(View on GitHub (pinned to fad1729dce)