{"record":{"id":"9a43de8e12422007","repo":"hibernate/hibernate-orm","slug":"can-t-emulate-json-objectagg-with-unique-keys-cl-9a43de","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/PostgreSQLJsonObjectAggFunction.java","lineNumber":42,"sourceCode":"\n\tpublic PostgreSQLJsonObjectAggFunction(boolean supportsStandard, TypeConfiguration typeConfiguration) {\n\t\tsuper( \":\", true, typeConfiguration );\n\t\tthis.supportsStandard = supportsStandard;\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\tif ( supportsStandard ) {\n\t\t\tsuper.render( sqlAppender, arguments, filter, returnType, translator );\n\t\t}\n\t\telse {\n\t\t\tif ( arguments.uniqueKeysBehavior() == JsonObjectAggUniqueKeysBehavior.WITH ) {\n\t\t\t\tthrow new QueryException( \"Can't emulate json_objectagg 'with unique keys' clause.\" );\n\t\t\t}\n\t\t\tfinal String jsonTypeName = translator.getSessionFactory().getTypeConfiguration().getDdlTypeRegistry()\n\t\t\t\t\t.getTypeName( SqlTypes.JSON, translator.getSessionFactory().getJdbcServices().getDialect() );\n\t\t\tsqlAppender.appendSql( jsonTypeName );\n\t\t\tsqlAppender.appendSql( \"_object_agg\" );\n\t\t\tsqlAppender.appendSql( '(' );\n\t\t\targuments.key().accept( translator );\n\t\t\tsqlAppender.appendSql( ',' );\n\t\t\targuments.value().accept( translator );\n\t\t\tsqlAppender.appendSql( ')' );\n\n\t\t\tif ( filter != null ) {\n\t\t\t\ttranslator.getCurrentClauseStack().push( Clause.WHERE );\n\t\t\t\tsqlAppender.appendSql( \" filter (where \" );\n\t\t\t\tfilter.accept( translator );\n\t\t\t\tif ( arguments.nullBehavior() != JsonNullBehavior.NULL ) {\n\t\t\t\t\tsqlAppender.appendSql( \" and \" );\n\t\t\t\t\targuments.value().accept( translator );","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/dialect/function/json/PostgreSQLJsonObjectAggFunction.java#L24-L60","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 (PostgreSQL).","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 (PostgreSQL).","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"}