ConstraintViolationException VS DataIntegrityViolationException

I am writing a Spring application, and it seems that when I encounter database errors, sometimes a Hibernate ConstraintViolationException is DataIntegrityViolationException , and sometimes a Spring DataIntegrityViolationException . Is there a reason why you can challenge and not another? Do they mean different things?

+6
spring hibernate
source share
1 answer

If you make Hibernate calls through the HibernateTemplate , then Spring translates any Hibernate exceptions (e.g. ConstraintViolationException ) into the Spring exception hierarchy (e.g. DataIntegrityViolationException ). If you are not using HibernateTemplate , then Hibernate's own exceptions will be thrown. Both values ​​are RuntimeExceptions , so explicit exception handling is not required, so it is not always obvious which one you will see.

+4
source share

All Articles