【问题标题】:org.hibernate.util.JDBCExceptionReporter] Duplicate entry X for key 'PRIMARY'org.hibernate.util.JDBCExceptionReporter] 键“PRIMARY”的重复条目 X
【发布时间】:2013-07-22 03:01:45
【问题描述】:

我在生产者消费者模型中使用active-mq 编写后端java 代码。当多个消费者使用并尝试更新表问题时,会发生以下异常并且事务被回滚。每个消费者任务中都运行多个线程。

WARN  [org.hibernate.util.JDBCExceptionReporter] SQL Error: 1062, SQLState: 23000

07:10:31,609 ERROR [org.hibernate.util.JDBCExceptionReporter] Duplicate entry '69-947' for key 'PRIMARY'

07:10:31,615 ERROR [com.xminds.bestfriend.consumers.QuestionGeneration] Exception failed the Question generation 

org.springframework.dao.DataIntegrityViolationException: could not insert: [com.xminds.bestfriend.frontend.model.Friendship];

任何人都可以为此提出解决方案。

【问题讨论】:

  • Duplicate entry '69-947' for key 'PRIMARY' ,似乎两个线程正在尝试插入具有相同 PK 的记录!你如何生成PK
  • 我正在为我们的应用程序从 facebook 获取流数据,并且在表中 post_id 用作主键。
  • 我想知道PK是谁生成的?它是自动生成的还是您提供 PK

标签: java multithreading activemq


【解决方案1】:

我认为您正在尝试使用现有主键插入记录。确保主键是唯一的。

【讨论】:

    【解决方案2】:

    您的数据库中有一个约束。表中的主键重复,您应该为您的表使用自动生成的 id

    【讨论】:

    • Facebook post_id 用作主键,因为在我的应用程序中,facebook 流数据存储在 hbm.xml 的表中,如下所示
    • 你应该试试
    猜你喜欢
    • 2017-02-17
    • 2012-07-23
    • 2013-09-30
    • 2015-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-20
    相关资源
    最近更新 更多