I have a mapped super class with an id field in it:
@Column(unique = true, length = 16, nullable = false)
@jakarta.persistence.Id
private UUID id = UUID.randomUUID();
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 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 correctly (I have no idea why):
public class AlternativeH2Dialect extends H2Dialect {}
Unfortunately this no longer works in 6.2.0 and 6.2.1. The error message I receive is the following:
Note that here the found type is correct, while the expected type is wrong. 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:
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:
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. |