When a unique constraint is violated, a javax.persistence.RollbackException
is thrown. But there could be multiple reasons to throw a RollbackException
compiler returns the exception SQLIntegrityConstraintViolationException, while trying to violate unique constraint.
Use the following catch block concept, to handle proper exceptions.
catch(SQLIntegrityConstraintViolationException e)
{
// Error message for integrity constraint violation
}
catch(Exception e)
{
// Other error messages
}