Kevin Meredith
Kevin Meredith

Reputation: 41939

Hibernate DDL v. Validator Annotations

My understanding is that Hibernate's Annotations fall into 2 categories:

In this helpful answer, Pascal Thivent explains the difference between @Column and @Size.

As I understand Hibernate Validator, their annotations will take effect regardless of whether DDL is enabled or not.

Please confirm/deny my understanding of Annotations, as well as Hibernate Validator's impact whether DDL is enabled/disabled.

Upvotes: 1

Views: 162

Answers (1)

Simone Gianni
Simone Gianni

Reputation: 11672

The validator will work even if the DDL has not been generated by hibernate. The annotations, despite overlapping semantically, are different ones.

This in practice reflects two different validations: one is the bean validation done in your application, the other is the database validation done by the db.

For example, a property with @Size(max=50) and @Column(length=40) will pass the application-side validation fir a string of length 45, but will fail with an SQL exception is on the database the DDL say the column is VARCHAR(40). This is redundant and usually useless, but maybe helps you understand.

Upvotes: 1

Related Questions