{"record":{"id":"fd77c0aabc0703d9","repo":"quarkusio/quarkus","slug":"flush-failed-for-a-different-reason-than-expected","errorCode":null,"errorMessage":"flush failed for a different reason than expected.","messagePattern":"flush failed for a different reason than expected\\.","errorType":"http","errorClass":"AssertionError","httpStatus":500,"severity":"warning","filePath":"integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java","lineNumber":172,"sourceCode":"\n        Exception exception = null;\n        try {\n            QuarkusTransaction.requiringNew().run(() -> {\n                EntityWithJsonOtherPU otherPU = new EntityWithJsonOtherPU(\n                        new EntityWithJsonOtherPU.ToBeSerializedWithDateTime(LocalDate.of(2023, 7, 28)));\n                otherEm.persist(otherPU);\n            });\n        } catch (Exception e) {\n            exception = e;\n        }\n\n        if (exception == null) {\n            throw new AssertionError(\n                    \"Default mapper cannot process date/time properties. So we were expecting transaction to fail, but it did not!\");\n        }\n        if (!(exception instanceof UnsupportedOperationException)\n                || !exception.getMessage().contains(\"I cannot convert anything to JSON\")) {\n            throw new AssertionError(\"flush failed for a different reason than expected.\", exception);\n        }\n\n        return \"OK\";\n    }\n\n}\n","sourceCodeStart":154,"sourceCodeEnd":179,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/jpa-postgresql/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java#L154-L179","documentation":"In the same json endpoint, after catching the expected flush failure the test validates that the exception is an UnsupportedOperationException whose message contains 'I cannot convert anything to JSON'. Any other exception type or message triggers this AssertionError, indicating the flush failed for an unanticipated reason.","triggerScenarios":"Flush during persist of a JSON entity failing with an unexpected exception — e.g. SQLException from PostgreSQL, ClassCastException in the JSON binder, or a wrapped constraint violation — instead of the mapper's UnsupportedOperationException.","commonSituations":"Schema mismatch (column not json type), serialization errors from a custom ObjectMapper, Hibernate version upgrade changing exception wrapping, or connection/schema errors during flush.","solutions":["Log the caught exception's class and message to see the actual failure","Verify the json column exists with the correct type in the PostgreSQL schema","Check that no custom mapper replaced the default JSON mapper","Align the assertion with the exception type/message produced by the current Hibernate version"],"exampleFix":"// before\nif (!(exception instanceof UnsupportedOperationException)\n        || !exception.getMessage().contains(\"I cannot convert anything to JSON\")) {\n    throw new AssertionError(\"flush failed for a different reason than expected.\", exception);\n}\n// after (diagnostic first)\nSystem.out.println(\"caught: \" + exception.getClass() + \": \" + exception.getMessage());","handlingStrategy":"try-catch","validationCode":"// inspect actual failure before asserting\nif (exception != null) {\n    System.out.println(\"caught \" + exception.getClass().getName() + \": \" + exception.getMessage());\n}","typeGuard":null,"tryCatchPattern":"try {\n    em.flush();\n} catch (UnsupportedOperationException e) {\n    if (!e.getMessage().contains(\"I cannot convert anything to JSON\")) {\n        throw new AssertionError(\"unexpected mapper message\", e);\n    }\n} catch (RuntimeException e) {\n    throw new AssertionError(\"flush failed for an unexpected reason\", e);\n}","preventionTips":["Catch specific exception types separately from generic RuntimeException","Verify schema/json column types when flush fails","Re-check assertion strings after upgrading Hibernate versions","Log the full exception chain for wrapped persistence errors"],"tags":["jpa","postgresql","json","exception-mapping","test-assertion"],"backgroundTag":"json-serialization-unsupported-type","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}