【发布时间】: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