1

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

  • Only take effect if Hibernate DDL is enabled (means that Hibernate can create/update/delete the DB schema
  • Hibernate Validator uses them

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.

Community
  • 1
  • 1
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384

1 Answers1

1

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.

Simone Gianni
  • 11,426
  • 40
  • 49