Using JPA/Hibernate, defining an entity with the following field:
@Id
@Column(length = 36)
private String id = UUID.randomUUID().toString();
Using Liquibase, knowing that this is a UUID, having the following in the change log:
<column name="id" type="uuid">
...
We like to use Hibernate's hbm2ddl.auto=validate
/ddl-auto=validate
on startup. Now, for MySQL, Hibernate is going to think this should be VARCHAR
, while we know the length is fixed, CHAR
, which Liquibase can derive from type="uuid"
(in fact, Liquibase defines this in its UUIDType
). So the Hibernate validation on startup is going to balk about the type difference between VARCHAR
and CHAR
.
How to fix this problem in a canonical way? Canonical means for me:
- Don't compromise on
type="uuid"
in the Liquibase change log - Don't use
@Column(..., columnDefinition="CHAR")
since that's not strictly portable
(I'm currently working around this by having my own override of Liquibase's UUIDType
and make the column a VARCHAR
, but CHAR
seems better, strictly speaking, anyway. And this seems like an overkill solution.)
Clearly, this is not an immediate problem (as I have the workaround), but I'd like to learn the right way to do this.