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?
views:
265answers:
1
+1
A:
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.
skaffman
2009-08-07 22:55:14