john doe (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=60c6117...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNjlmYjY4ZDky...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16476?atlOrigin=eyJpIjoiNjlmYj...
) HHH-16476 (
https://hibernate.atlassian.net/browse/HHH-16476?atlOrigin=eyJpIjoiNjlmYj...
) hibernate and h2 database UUID validation error (
https://hibernate.atlassian.net/browse/HHH-16476?atlOrigin=eyJpIjoiNjlmYj...
)
Issue Type: Bug Affects Versions: 6.2.0, 6.2.1 Assignee: Unassigned Components:
hibernate-core Created: 15/Apr/2023 06:08 AM Environment: hibernate 6.2.0/6.2.1
h2 2.1.214
spring boot 3.1.0-M2
liquibase 4.21.1
java 20 Priority: Major Reporter: john doe (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=60c6117...
)
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:
Schema-validation: wrong column type encountered in column [id] in table [`xyz`]; found
[binary (Types#BINARY)], but expecting [uuid (Types#UUID)]
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:
@Column(columnDefinition = "binary")
@jakarta.persistence.Id
private UUID id = UUID.randomUUID();
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:
Schema-validation: wrong column type encountered in column [id] in table
[`absence_report`]; found [binary (Types#BINARY)], but expecting ["binary"
(Types#UUID)]
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 )