I am writing a Spring app, and it seems that when I run into database errors, sometimes Hibernate's ConstraintViolationException
is thrown and sometimes Spring's DataIntegrityViolationException
is thrown. Is there a reason one might be thrown and not the other? Do they mean different things?
If you execute Hibernate calls via the HibernateTemplate
, then Spring will translate any Hibernate exceptions (e.g. ConstraintViolationException
) into the Spring exception hierarchy (e.g. DataIntegrityViolationException
). If you don't use HibernateTemplate
, then the native Hibernate exceptions will go through. Both are RuntimeExceptions
, so don't need explicit exception handling, so it's not always obvious which one you're going to see.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With