Reputation: 2243
I got following definition on a createTable in liquibase:
<column name="FOO" type="CHAR(3)">
<constraints nullable="false"/>
</column>
When I run this agains a local postgres:latest docker database the datatype is correctly setup as CHAR(3).
When I now define my entity with the following:
@Column(name = "FOO", nullable = false, length = 3, columnDefinition = "char")
private String foo;
and enable jpa-validation in spring-boot I get the following error:
Schema-validation: wrong column type encountered in column [foo] in table [my_schema.my_table]; found [bpchar (Types#CHAR)], but expecting [char(3) (Types#VARCHAR)]
Why? And how can I fix this? The field is allowed to be exactly 3 characters all the time.
EDIT: There is no bpchar and I think hibernate does not pick this up correctly: https://docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#basic-provided
Upvotes: 0
Views: 208
Reputation: 678
Hibernate ignores columnDefinition
in validation, only for initialization. To set a column type use @JdbcTypeCode
annotation:
@JdbcTypeCode(SqlTypes.CHAR)
@Column(name = "FOO", nullable = false, length = 3)
private String foo;
Upvotes: 1