{"record":{"id":"cb896aab6442ad9d","repo":"hibernate/hibernate-orm","slug":"can-t-emulate-on-error-clause-on-postgresql-cb896a","errorCode":null,"errorMessage":"Can't emulate on error clause on PostgreSQL","messagePattern":"Can't emulate on error clause on PostgreSQL","errorType":"exception","errorClass":"QueryException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/dialect/function/json/PostgreSQLJsonValueFunction.java","lineNumber":62,"sourceCode":"\t\t\tif ( isBinary ) {\n\t\t\t\tsqlAppender.appendSql( \"decode(\" );\n\t\t\t}\n\t\t\tsuper.render( sqlAppender, arguments, returnType, walker );\n\t\t\t// PostgreSQL unfortunately renders `t`/`f` for JSON booleans instead of `true`/`false` like every other DB.\n\t\t\t// To work around this, extract the jsonb node directly and then use the `#>>` operator to unquote values\n\t\t\t// Also see https://stackoverflow.com/questions/79483975/postgresql-json-value-boolean-behavior\n\t\t\tif ( isString( arguments.returningType() ) ) {\n\t\t\t\t// Unquote the value\n\t\t\t\tsqlAppender.appendSql( \"#>>'{}'\" );\n\t\t\t}\n\t\t\telse if ( isBinary ) {\n\t\t\t\tsqlAppender.appendSql( \",'hex')\" );\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\t// jsonb_path_query_first errors by default\n\t\t\tif ( arguments.errorBehavior() != null && arguments.errorBehavior() != JsonValueErrorBehavior.ERROR ) {\n\t\t\t\tthrow new QueryException( \"Can't emulate on error clause on PostgreSQL\" );\n\t\t\t}\n\t\t\tif ( arguments.emptyBehavior() != null && arguments.emptyBehavior() != JsonValueEmptyBehavior.NULL ) {\n\t\t\t\tthrow new QueryException( \"Can't emulate on empty clause on PostgreSQL\" );\n\t\t\t}\n\n\t\t\tappendJsonValue(\n\t\t\t\t\tsqlAppender,\n\t\t\t\t\targuments.jsonDocument(),\n\t\t\t\t\targuments.jsonPath(),\n\t\t\t\t\targuments.isJsonType(),\n\t\t\t\t\targuments.returningType(),\n\t\t\t\t\targuments.passingClause(),\n\t\t\t\t\twalker\n\t\t\t);\n\t\t}\n\t}\n\n\t@Override","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/dialect/function/json/PostgreSQLJsonValueFunction.java#L44-L80","documentation":"Error \"Can't emulate on error clause on PostgreSQL\" 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 on error clause on 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 on error clause on PostgreSQL.","solutions":["Remove the ON ERROR clause for PostgreSQL."],"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"}