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

Error "Slice operator applied to expression of unknown type" thrown in hibernate/hibernate-orm.

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)

Solutions

  1. 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.

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.