liquibase-hibernate
liquibase-hibernate copied to clipboard
javax.validation.constraints are not included in diffs
Using a validation constraint annotation (i.e. javax.validation.constraints.NotNull
) does not produce a NOT NULL
constraint in the Liquibase migration. The same issue happens with using other javax constraints like @Size
liquibaseRuntime 'org.liquibase:liquibase-core:4.3.1'
liquibaseRuntime 'org.liquibase.ext:liquibase-hibernate5:4.3.0.1'
The only way to have Liquibase generate NOT NULL
in the migration is to use the @Column(nullable = false)
annotation. This is bad though because then the check happens at the database layer as opposed to in the Java layer. The only way to have Java validate the constraint as well as have Liquibase generate the correct migration is to duplicate both annotations like this:
@Column(nullable = false)
@NotNull
Similar example for max size:
@Column(length = 100)
@Size(max = 100)
It's an issue with liquibase-hibernate5
as opposed to Hibernate because if I disable Liquibase and let Hibernate generate the schema, it will correctly generate the NOT NULL
in the database with just @NotNull
annotation as expected. The additional @Column
annotation is only required when using Liquibase.
For some reason, my liquibase installation removes NOT NULL
constraint even if I provide @Column(nullable = false)
annotation.
@Column(nullable = false)
@NotNull
private String acronym;
<...>
-- changeset bohdan:1659912623805-1
ALTER TABLE public.teams ALTER COLUMN acronym DROP NOT NULL;
Ugh, oh. Just launched ./gradlew compileJava
and DROP NOT NULL
had gone. It is quite unobvious. Maybe, I'm not a good doc reader, who knows. 🤷
However, @NotNull
is ignored, like always.