I can’t understand why I’m not getting a DataIntegrityViolationException any more after upgrading from Hibernate Validator 3.X to 4.X.
Somehow Spring is not able to wrap the persistence layer exceptions anymore.
Nothing has changed except the Validator dependency but the test validating that DataIntegrityViolationException is thrown in case of validation violation doesn’t pass anymore.
I now get a javax.validation.ConstraintViolationException instead.
Everything is still in place, including of course the
but translation doesn’t happen anymore.
help welcome!
According to JPA-2.0 specification, JSR-303 validation is automatically triggered before persisting an entity if JSR-303 validator implementation (i.e. Hibernate Validator 4.x) is present in the classpath.
So, your entity is rejected by Hibernate Validator and don’t get into the database, thus database integrity constraint is not violated and
DataIntegrityViolationExceptionis not thrown, and you get JSR-303’sConstraintViolationExceptioninstead.You can disable this default behaviour by adding
to your
persistence.xml.