john doe (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=60c6117...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZDViYWY1NWQ1...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16476?atlOrigin=eyJpIjoiZDViYW...
) HHH-16476 (
https://hibernate.atlassian.net/browse/HHH-16476?atlOrigin=eyJpIjoiZDViYW...
) hibernate and h2 database UUID validation error (
https://hibernate.atlassian.net/browse/HHH-16476?atlOrigin=eyJpIjoiZDViYW...
)
Change By: john doe (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=60c6117...
)
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.atlassi...]
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.
(
https://hibernate.atlassian.net/browse/HHH-16476#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16476#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100221- sha1:8830b7c )