【问题标题】:Specific information from ConstraintViolationException来自 ConstraintViolationException 的具体信息
【发布时间】:2018-01-02 21:26:31
【问题描述】:

我对列名和电子邮件有唯一的限制,当 JPA 抛出 ConstraintViolationException 时,我需要知道哪一列被违反了,但我只得到:

{
    "timestamp": 1501144724882,
    "status": 500,
    "error": "Internal Server Error",
    "exception": "org.springframework.dao.DataIntegrityViolationException",
    "message": "could not execute statement; SQL [n/a]; constraint [uk_6dotkott2kjsp8vw4d0m25fb7]; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement",
    "path": "/add"
}

我使用 PostgreSQL 数据库。

【问题讨论】:

  • 发布您的查询/声明
  • 我通过 Spring JpaRepository 使用方法 save 保存它
  • 问题里加代码和数据库查询会更好
  • 我不使用sql查询。我使用 Spring Data

标签: java postgresql hibernate jpa jdbc


【解决方案1】:

你得到 DataIntegrityViolationException ,对于约束的名称 uk_6dotkott2kjsp8vw4d0m25fb7 检查 db 它是什么约束。首先签入您尝试添加/保存元素的表。它看起来像自动生成的约束,所以没有访问数据库很难说这个约束是什么。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-07
    • 1970-01-01
    • 1970-01-01
    • 2015-07-21
    • 1970-01-01
    • 1970-01-01
    • 2015-05-17
    相关资源
    最近更新 更多