Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

javax.validation.constraints are not included in diffs #301

Open
bobbywarner opened this issue Feb 22, 2021 · 2 comments
Open

javax.validation.constraints are not included in diffs #301

bobbywarner opened this issue Feb 22, 2021 · 2 comments

Comments

@bobbywarner
Copy link

bobbywarner commented Feb 22, 2021

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.

┆Issue is synchronized with this Jira Bug by Unito

@bohdan-shulha
Copy link

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;

@bohdan-shulha
Copy link

bohdan-shulha commented Aug 7, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants