{"record":{"id":"4a8a4ebb76ed0cba","repo":"quarkusio/quarkus","slug":"flush-failed-for-a-different-reason-than-expected-4a8a4e","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":"error","filePath":"integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java","lineNumber":234,"sourceCode":"\n        Exception exception = null;\n        try {\n            QuarkusTransaction.requiringNew().run(() -> {\n                EntityWithXmlOtherPU otherPU = new EntityWithXmlOtherPU(\n                        new EntityWithXmlOtherPU.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                    \"Our custom XML format mapper throws exceptions. 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 XML\")) {\n            throw new AssertionError(\"flush failed for a different reason than expected.\", exception);\n        }\n\n        return \"OK\";\n    }\n\n}\n","sourceCodeStart":216,"sourceCodeEnd":241,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java#L216-L241","documentation":"This AssertionError is thrown by a test endpoint when a Hibernate ORM flush fails, but the failure is not the expected UnsupportedOperationException with message 'I cannot convert anything to XML'. The test registers a custom FormatMapper (XmlFormatMapper) that always throws for the 'other' persistence unit, so persisting an entity with an XML-serialized property must fail with exactly that exception. Any other failure mode (wrong exception type, different message, rollback not happening) means the application wiring or expected behavior is broken.","triggerScenarios":"Persisting an entity mapped to the 'other' persistence unit whose property uses @JdbcTypeCode(SqlTypes.JSON) with XML format, when the flush fails for a reason other than UnsupportedOperationException('I cannot convert anything to XML') — e.g. the custom mapper is not selected, the mapper throws a different exception, or the transaction unexpectedly succeeds with a different error.","commonSituations":"Hitting this during test runs of the jpa-postgresql-withxml integration test after changing Hibernate ORM version behavior around FormatMapper, renaming or un-annotating the @PersistenceUnitExtension(\"other\") mapper so a different mapper is picked, or changing the entity mapping so serialization no longer goes through the XML mapper.","solutions":["Inspect the wrapped cause (the AssertionError carries the real exception) and check why the flush failed instead of via XmlFormatMapper.toString","Verify XmlFormatMapper is annotated with both @XmlFormat and @PersistenceUnitExtension(\"other\") so it is selected for that persistence unit","Confirm the entity's property uses the XML serialization path (SqlTypes.JSON with format mapping) so Hibernate routes through the FormatMapper","Rebuild the module and re-run the test; if Hibernate changed exception wrapping, update the assertion to unwrap (e.g. check cause chain)"],"exampleFix":"// before\nif (!(exception instanceof UnsupportedOperationException)\n        || !exception.getMessage().contains(\"I cannot convert anything to XML\")) {\n    throw new AssertionError(\"flush failed for a different reason than expected.\", exception);\n}\n// after\nThrowable root = exception;\nwhile (root.getCause() != null) { root = root.getCause(); }\nif (!(root instanceof UnsupportedOperationException)\n        || !root.getMessage().contains(\"I cannot convert anything to XML\")) {\n    throw new AssertionError(\"flush failed for a different reason than expected.\", exception);\n}","handlingStrategy":"try-catch","validationCode":"// Ensure the XML format mapper is wired for the PU before running the flow\nFormatMapper mapper = ...; // resolve mapper for 'other' PU\nif (!(mapper instanceof XmlFormatMapper)) {\n    throw new IllegalStateException(\"XmlFormatMapper not bound to 'other' persistence unit\");\n}","typeGuard":"static boolean isExpectedFlushFailure(Throwable t) {\n    while (t != null) {\n        if (t instanceof UnsupportedOperationException\n                && t.getMessage() != null\n                && t.getMessage().contains(\"I cannot convert anything to XML\")) {\n            return true;\n        }\n        t = t.getCause();\n    }\n    return false;\n}","tryCatchPattern":"try {\n    QuarkusTransaction.requiringNew().run(() -> em.persist(otherPU));\n    throw new AssertionError(\"Expected transaction to fail\");\n} catch (Exception e) {\n    if (!isExpectedFlushFailure(e)) {\n        throw new AssertionError(\"flush failed for a different reason than expected.\", e);\n    }\n}","preventionTips":["Always unwrap the full cause chain when asserting on persistence-layer exceptions (Hibernate wraps them)","Assert on exception message content, not just type, when the flow can throw multiple UnsupportedOperationExceptions","Keep the @PersistenceUnitExtension qualifier consistent with the entity's persistence unit","Re-verify assertions after Hibernate ORM minor upgrades, as exception wrapping can change"],"tags":["hibernate-orm","assertion","format-mapper","test"],"backgroundTag":"unexpected-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"}