ConstraintViolationException VS DataIntegrityViolationException
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 (eg ConstraintViolationException
) into the Spring exception hierarchy (eg 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.
上一篇: 如何在ActionLink的字符串部分添加NEW LINE字符?
下一篇: ConstraintViolationException VS DataIntegrityViolationException