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

Bean validation constraints not honored #149

Open
llowrey opened this issue Apr 21, 2017 · 2 comments
Open

Bean validation constraints not honored #149

llowrey opened this issue Apr 21, 2017 · 2 comments

Comments

@llowrey
Copy link

llowrey commented Apr 21, 2017

I'm using liquibase-maven-plugin version 3.5.3 and running liquibase:diff with the following reference:

referenceUrl=hibernate:spring:com.example.package.model?dialect=org.hibernate.dialect.MySQL57InnoDBDialect

When I have a String field annotated with @Length(max=65535) liquibase assigns the column a type of varchar(255) but hibernate assigns it varchar(65535). Likewise, with I use @NotNull liquibase does not apply a "nullable: false" constraint but hibernate does.

Hibernate does apply the bean validation annotation logic to construct correct metadata during EntityManagerFactoryBuilderImpl.build() but somehow that metadata is lost. When the plugin creates metadata through the MetadataSources process the bean validation annotations are not processed.

I believe the process by which metadata is being extracted is unnecessary. You can get the metadata directly from EntityManagerFactoryBuilderImpl without going through the MetadataSources process. The metadata you get from the builder has the annotations processed as expected.

EntityManagerFactory emf = builder.build();
for (Table table : mi.collectTableMappings()) {
    System.out.printf("Table '%s'%n", table.getName());
    Iterator<?> i = table.getColumnIterator();
    while (i.hasNext()) {
        Column col = (Column)i.next();
        System.out.printf("\tcol:%s %s %d %b%n", col.getName(), col.getSqlType(dialect, null), col.getLength(), col.isNullable());
    }
}

Has this technique already been considered? Has anyone else experienced the issue with bean validation constraints? Does it work for everyone else and I doing something wrong?

┆Issue is synchronized with this Jira Bug by Unito

@gdenchev
Copy link

I am a bit late to the party, but I have the same problem here.
I am using the hibernate:spring:packageNames url format, and @NotNull and @SiZe are not honored.

Unfortunately, I have merged your pull request and tried, but cannot get it to work.
Annotations are still not honored ...
Can you please post your working configuration?

@llowrey
Copy link
Author

llowrey commented Nov 22, 2018

I never came up with a complete solution and ended up solving my problem with a non-liquibase solution.

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

4 participants