{"record":{"id":"28ccca6894b3da4a","repo":"hibernate/hibernate-orm","slug":"can-t-emulate-json-objectagg-with-unique-keys-cl-28ccca","errorCode":null,"errorMessage":"Can't emulate json_objectagg 'with unique keys' clause.","messagePattern":"Can't emulate json_objectagg 'with unique keys' clause\\.","errorType":"exception","errorClass":"QueryException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/dialect/function/json/MySQLJsonObjectAggFunction.java","lineNumber":36,"sourceCode":"/**\n * MySQL json_objectagg function.\n */\npublic class MySQLJsonObjectAggFunction extends JsonObjectAggFunction {\n\n\tpublic MySQLJsonObjectAggFunction(TypeConfiguration typeConfiguration) {\n\t\tsuper( \",\", false, typeConfiguration );\n\t}\n\n\t@Override\n\tprotected void render(\n\t\t\tSqlAppender sqlAppender,\n\t\t\tJsonObjectAggArguments arguments,\n\t\t\tPredicate filter,\n\t\t\tReturnableType<?> returnType,\n\t\t\tSqlAstTranslator<?> translator) {\n\t\tfinal boolean caseWrapper = filter != null;\n\t\tif ( arguments.uniqueKeysBehavior() == JsonObjectAggUniqueKeysBehavior.WITH ) {\n\t\t\tthrow new QueryException( \"Can't emulate json_objectagg 'with unique keys' clause.\" );\n\t\t}\n\t\tsqlAppender.appendSql( \"concat('{',group_concat(concat(json_quote(\" );\n\t\targuments.key().accept( translator );\n\t\tsqlAppender.appendSql( \"),':',\" );\n\t\tif ( caseWrapper ) {\n\t\t\tif ( arguments.nullBehavior() != JsonNullBehavior.ABSENT ) {\n\t\t\t\tthrow new QueryException( \"Can't emulate json_objectagg filter clause when using 'null on null' clause.\" );\n\t\t\t}\n\t\t\ttranslator.getCurrentClauseStack().push( Clause.WHERE );\n\t\t\tsqlAppender.appendSql( \"case when \" );\n\t\t\tfilter.accept( translator );\n\t\t\ttranslator.getCurrentClauseStack().pop();\n\t\t\tsqlAppender.appendSql( \" then \" );\n\t\t\trenderArgument( sqlAppender, arguments.value(), arguments.nullBehavior(), translator );\n\t\t\tsqlAppender.appendSql( \" else null end)\" );\n\t\t}\n\t\telse {\n\t\t\trenderArgument( sqlAppender, arguments.value(), arguments.nullBehavior(), translator );","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/dialect/function/json/MySQLJsonObjectAggFunction.java#L18-L54","documentation":"Error \"Can't emulate json_objectagg 'with unique keys' clause.\" thrown in hibernate/hibernate-orm.","triggerScenarios":"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).","commonSituations":"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).","solutions":["Remove the WITH UNIQUE KEYS clause."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}