john doe (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=60c6117...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiZTRkM2Y2OTlh...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16476?atlOrigin=eyJpIjoiZTRkM2...
) HHH-16476 (
https://hibernate.atlassian.net/browse/HHH-16476?atlOrigin=eyJpIjoiZTRkM2...
) hibernate and database column type validation error (
https://hibernate.atlassian.net/browse/HHH-16476?atlOrigin=eyJpIjoiZTRkM2...
)
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 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
A different aspect of this error, against mysql database. Suppose I have an enum field
that I want to store in the database by text instead of by ordinal. For this I have the
following definition:
{noformat}(a)Enumerated(EnumType.STRING)
@Column(length = 20)
private MyEnumType myEnumValue;{noformat}
If I ask Spring to create the database from scratch, this creates the following column
type:
{noformat}...
`myEnumValue`
enum('VALUE_A','VALUE_B','VALUE_C','VALUE_D') DEFAULT
NULL,
...{noformat}
When the application starts up a second time in validation mode, the validation fails with
the following error message:
{noformat}Schema-validation: wrong column type encountered in column [my_enum_type] in
table [`xyz`]; found [enum (Types#CHAR)], but expecting [varchar(20)
(Types#VARCHAR)]{noformat}
Here again, as far as I can tell, the database reports the (a?) correct type, and the
expectation seems off. However I do not receive the same validation error when working
against an h2 instance. So either h2 creates and reports this field differently from
mysql, or the expectations of hibernate are different for the two databases for this
field, or both.
The database version versions (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 )