views:

265

answers:

1

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?

+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