我在生產者消費者模型中編寫了一個active-mq
的後端java代碼。當多個使用者運行並嘗試在表問題中更新時,會發生以下異常,並且事務將被回滾。每個消費者任務中都運行多個線程。org.hibernate.util.JDBCExceptionReporter]鍵'PRIMARY'的重複項X
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];
任何人都可以爲此提出解決方案。
'關鍵'PRIMARY''的重複條目'69 -947',看起來兩個線程試圖插入一個具有相同'PK'的記錄。 !你如何生成'PK'? – NINCOMPOOP
我正在從我們的應用程序的facebook的流數據和表內post_id被用作主鍵。 – Vishnupriya
我想知道誰生成'PK'?它是自動生成還是您提供'PK'? – NINCOMPOOP