hibernate/hibernate-orm · error · QueryException
JSON path does not point to a valid array index: ${jsonPath}
Error message
JSON path does not point to a valid array index: ${jsonPath} What it means
Error "JSON path does not point to a valid array index: ${jsonPath}" thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/dialect/function/json/SQLServerJsonArrayInsertFunction.java:45
public void render(
SqlAppender sqlAppender,
List<? extends SqlAstNode> arguments,
ReturnableType<?> returnType,
SqlAstTranslator<?> translator) {
final String jsonPath = translator.<String>getLiteralValue( (Expression) arguments.get( 1 ) ).trim();
final int bracketEndIndex = jsonPath.lastIndexOf( ']' );
final int bracketStartIndex = jsonPath.lastIndexOf( '[' );
if ( jsonPath.isEmpty()
|| bracketEndIndex != jsonPath.length() - 1
|| bracketStartIndex == -1 ) {
throw new QueryException( "JSON path does not end with an array index: " + jsonPath );
}
final int index;
try {
index = Integer.parseInt( jsonPath.substring( bracketStartIndex + 1, bracketEndIndex ) );
}
catch ( NumberFormatException e ) {
throw new QueryException( "JSON path does not point to a valid array index: " + jsonPath );
}
final Expression json = (Expression) arguments.get( 0 );
final SqlAstNode value = arguments.get( 2 );
// Only replace data if this is an array
sqlAppender.appendSql( "(select case when left(json_query(x.d,x.p),1)='[' then " );
// Replace the array
sqlAppender.appendSql( "json_modify(x.d,x.p,json_query((" );
// Aggregate a new JSON array based on element rows
sqlAppender.appendSql( "select '['+string_agg(t.v,',') within group (order by t.k)+']' from (" );
sqlAppender.appendSql( "select x.i k,x.v v union all " );
sqlAppender.appendSql( "select case when cast(t.[key] as int)>=x.i then cast(t.[key] as int)+1 " );
sqlAppender.appendSql( "else cast(t.[key] as int) end," );
// type 0 is a null literal
sqlAppender.appendSql( "case t.type when 0 then 'null' when 1 then ");
// type 1 is a string literal. to quote it, we use for json path and trim the string down to just the value
sqlAppender.appendSql(
"(select substring(a.v,6,len(a.v)-6) from (select t.value a for json path,without_array_wrapper) a(v))" );View on GitHub (pinned to fad1729dce)
Solutions
- Use a valid numeric array index within bounds.
When it happens
Trigger: Triggered when the application calls a Hibernate dialect feature that the configured database dialect cannot provide: JSON path does not point to a valid array index (SQL Server).
Common situations: Common when running against a database whose dialect lacks this capability, when a mapping or HQL/Criteria query requests unsupported functionality, or when the wrong dialect is configured for the database in use. Error: JSON path does not point to a valid array index (SQL Server).
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/ed95925f4818c1d6.
Report an issue: GitHub.