quarkusio/quarkus · error · AssertionError
flush failed for a different reason than expected.
Error message
flush failed for a different reason than expected.
What it means
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.
Source
Thrown at integration-tests/jpa-postgresql-withxml/src/main/java/io/quarkus/it/jpa/postgresql/JPAFunctionalityTestEndpoint.java:234
Exception exception = null;
try {
QuarkusTransaction.requiringNew().run(() -> {
EntityWithXmlOtherPU otherPU = new EntityWithXmlOtherPU(
new EntityWithXmlOtherPU.ToBeSerializedWithDateTime(LocalDate.of(2023, 7, 28)));
otherEm.persist(otherPU);
});
} catch (Exception e) {
exception = e;
}
if (exception == null) {
throw new AssertionError(
"Our custom XML format mapper throws exceptions. So we were expecting transaction to fail, but it did not!");
}
if (!(exception instanceof UnsupportedOperationException)
|| !exception.getMessage().contains("I cannot convert anything to XML")) {
throw new AssertionError("flush failed for a different reason than expected.", exception);
}
return "OK";
}
}
View on GitHub (pinned to e1c734241f)
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)
Example fix
// before
if (!(exception instanceof UnsupportedOperationException)
|| !exception.getMessage().contains("I cannot convert anything to XML")) {
throw new AssertionError("flush failed for a different reason than expected.", exception);
}
// after
Throwable root = exception;
while (root.getCause() != null) { root = root.getCause(); }
if (!(root instanceof UnsupportedOperationException)
|| !root.getMessage().contains("I cannot convert anything to XML")) {
throw new AssertionError("flush failed for a different reason than expected.", exception);
} Defensive patterns
Strategy: try-catch
Validate before calling
// Ensure the XML format mapper is wired for the PU before running the flow
FormatMapper mapper = ...; // resolve mapper for 'other' PU
if (!(mapper instanceof XmlFormatMapper)) {
throw new IllegalStateException("XmlFormatMapper not bound to 'other' persistence unit");
} Type guard
static boolean isExpectedFlushFailure(Throwable t) {
while (t != null) {
if (t instanceof UnsupportedOperationException
&& t.getMessage() != null
&& t.getMessage().contains("I cannot convert anything to XML")) {
return true;
}
t = t.getCause();
}
return false;
} Try / catch
try {
QuarkusTransaction.requiringNew().run(() -> em.persist(otherPU));
throw new AssertionError("Expected transaction to fail");
} catch (Exception e) {
if (!isExpectedFlushFailure(e)) {
throw new AssertionError("flush failed for a different reason than expected.", e);
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Incorrect number of results
- Not equal; expected: " + expected + ", actual: " + actual
- I cannot convert anything from JSON.
- I cannot convert anything to JSON.
- I cannot convert anything from XML.
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/4a8a4ebb76ed0cba.
Report an issue: GitHub.