You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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;
Using a validation constraint annotation (i.e.
javax.validation.constraints.NotNull
) does not produce aNOT NULL
constraint in the Liquibase migration. The same issue happens with using other javax constraints like@Size
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:Similar example for max size:
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 theNOT NULL
in the database with just@NotNull
annotation as expected. The additional@Column
annotation is only required when using Liquibase.┆Issue is synchronized with this Jira Bug by Unito
The text was updated successfully, but these errors were encountered: