Skip to content

DataIntegrityViolationException(java)

DataIntegrityViolationException (Spring Framework 5.3.21 API)
Exception thrown when an attempt to insert or update data results in violation of an integrity constraint. Note that this is not purely a relational concept; unique primary keys are required by most database types.

插入或者更新数据的时候违反了唯一性约束。 主要不是单纯的关系概念;唯一主键是大多数数据库类型所需的。

可能的问题常见问题分析:

  • integer out of range 数据越界可能造成这种报错
  • 主键重复
  • 字段长度超出约束值(字段过长)
  • 字段有非空约束
org.springframework.dao.DataIntegrityViolationException: 
### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: integer out of range

org.springframework.dao.DataIntegrityViolationException: 
### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: value too long for type character varying(20)
org.springframework.dao.DataIntegrityViolationException: 
### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: integer out of range

org.springframework.dao.DataIntegrityViolationException: 
### Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: value too long for type character varying(20)