I have a mapped super class with an id field in it:
{code:java}@Column(unique = true, length = 16, nullable = false) @jakarta.persistence.Id private UUID id = UUID.randomUUID();{code}
Against both mysql and h2 it generates the correct database schema. However at validation it runs into something similar to the known [https://hibernate.atlassian.net/browse/HHH-9835|https://hibernate.atlassian.net/browse/HHH-9835|smart-link] issue (I don’t think this is a duplicate of that bug). To work around it, I have a custom H2 dialect: based on that bug report, a {{registerColumnType}} call can work around the known issue. In hibernate 6.x this method is no longer available (and I couldn’t find how a replacement should work), however it didn't seem to be necessary either, using an empty dialect extending the h2 one made the validation worked work correctly (I have no idea why):
{code:java}public class AlternativeH2Dialect extends H2Dialect {}{code}
Unfortunately this no longer works in 6.2.0 and 6.2.1. The error message I receive is the following:
{noformat}Schema-validation: wrong column type encountered in column [id] in table [`xyz`]; found [binary (Types#BINARY)], but expecting [uuid (Types#UUID)]{noformat}
Note that here the found type is correct, while the expected type is wrong. (The UUID is automatically converted into binary representation. In 5.x I needed an {{AttributeConverter<UUID, byte[]>}} for this, but not since 6.x came out.) With the existing issue, the expected type was correct, and the found type was incorrect.
This is also the same error that I receive if I stay on hibernate 6.1.7, but I fall back to using the default {{org.hibernate.dialect.H2Dialect}}.
Another suggested workaround to the existing issue is to use a column definition. However that does not help here either. If I change the column definition to:
{noformat}@Column(columnDefinition = "binary") @jakarta.persistence.Id private UUID id = UUID.randomUUID();{noformat}
The error remains, just slightly changes. The sql types now match (aside from the double-quote in the expected type), but the sql type codes are still different:
{noformat}Schema-validation: wrong column type encountered in column [id] in table [`absence_report`]; found [binary (Types#BINARY)], but expecting ["binary" (Types#UUID)]{noformat}
Considering that h2 should have no idea what a UUID is, this feels like a bug on the hibernate side, and will become an upgrade blocker for me once spring boot 3.1.0-RC1 comes out next week.
The h2 database version (and everything else in the project) is the same, the only thing that changed is the hibernate version. |
|