How to handle JPA unique constraint violations?

后端 未结 8 1785
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-05 14:05

When a unique constraint is violated, a javax.persistence.RollbackException is thrown. But there could be multiple reasons to throw a RollbackException

8条回答
  •  时光取名叫无心
    2020-12-05 14:32

    You have to catch javax.persistence.PersistenceException. Thrown exception is org.hibernate.exception.ConstraintViolationException.

    Exception Message : org.hibernate.exception.ConstraintViolationException: Duplicate entry '893073116V-1234567' for key 'nic_account_no'

提交回复
热议问题