hibernate/hibernate-orm · error · QueryException
Can't emulate json_objectagg 'with unique keys' clause.
Error message
Can't emulate json_objectagg 'with unique keys' clause.
What it means
Error "Can't emulate json_objectagg 'with unique keys' clause." thrown in hibernate/hibernate-orm.
Source
Thrown at hibernate-core/src/main/java/org/hibernate/dialect/function/json/MySQLJsonObjectAggFunction.java:36
/**
* MySQL json_objectagg function.
*/
public class MySQLJsonObjectAggFunction extends JsonObjectAggFunction {
public MySQLJsonObjectAggFunction(TypeConfiguration typeConfiguration) {
super( ",", false, typeConfiguration );
}
@Override
protected void render(
SqlAppender sqlAppender,
JsonObjectAggArguments arguments,
Predicate filter,
ReturnableType<?> returnType,
SqlAstTranslator<?> translator) {
final boolean caseWrapper = filter != null;
if ( arguments.uniqueKeysBehavior() == JsonObjectAggUniqueKeysBehavior.WITH ) {
throw new QueryException( "Can't emulate json_objectagg 'with unique keys' clause." );
}
sqlAppender.appendSql( "concat('{',group_concat(concat(json_quote(" );
arguments.key().accept( translator );
sqlAppender.appendSql( "),':'," );
if ( caseWrapper ) {
if ( arguments.nullBehavior() != JsonNullBehavior.ABSENT ) {
throw new QueryException( "Can't emulate json_objectagg filter clause when using 'null on null' clause." );
}
translator.getCurrentClauseStack().push( Clause.WHERE );
sqlAppender.appendSql( "case when " );
filter.accept( translator );
translator.getCurrentClauseStack().pop();
sqlAppender.appendSql( " then " );
renderArgument( sqlAppender, arguments.value(), arguments.nullBehavior(), translator );
sqlAppender.appendSql( " else null end)" );
}
else {
renderArgument( sqlAppender, arguments.value(), arguments.nullBehavior(), translator );View on GitHub (pinned to fad1729dce)
Solutions
- Remove the WITH UNIQUE KEYS clause.
When it happens
Trigger: Triggered when the application calls a Hibernate dialect feature that the configured database dialect cannot provide: Can't emulate json_objectagg 'with unique keys' clause (MySQL).
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: Can't emulate json_objectagg 'with unique keys' clause (MySQL).
AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22).
Data as JSON: /api/errors/28ccca6894b3da4a.
Report an issue: GitHub.