Class DataIntegrityViolationException


public class DataIntegrityViolationException extends DataAccessException

A statement broke a rule the schema declares: a duplicate key, a foreign key with no row behind it, a NOT NULL or CHECK constraint.

Named after Spring's, and meant for the same use: telling a duplicate apart from a ConcurrencyFailureException or any other DataAccessException. Running the same work again repeats it. The failures recognized are:

  • PostgreSQL: every SQLSTATE of class 23 (23505 unique, 23503 foreign key, 23502 not null, 23514 check).
  • MySQL and MariaDB: every SQLSTATE of class 23, and the codes that carry it -- 1062 duplicate entry, 1451/1452 foreign key, 1048 column cannot be null.
  • SQLite: a "constraint failed" error, of whichever kind.

An ORM session reports a database failure as an unchecked exception with this one as its cause; isCauseOf(Throwable) finds it there.

  • Constructor Details

    • DataIntegrityViolationException

      public DataIntegrityViolationException(String message)
    • DataIntegrityViolationException

      public DataIntegrityViolationException(String message, Throwable cause)
  • Method Details

    • isCauseOf

      public static boolean isCauseOf(Throwable failure)

      Whether failure is an integrity violation or was caused by one, however many exceptions it has been wrapped in since.

      • failure: what was caught; null answers false