在測試hibernate時出現(xiàn)了如下異常:
[Duplicate key or integrity constraint violation message from server: "Duplicate entry 'rick0@foobar.com' for key 2"]; SQL was [] for task [Hibernate operation]
org.springframework.dao.DataIntegrityViolationException: Hibernate operation: Duplicate key or integrity constraint violation message from server: "Duplicate entry 'rick0@foobar.com' for key 2"; nested exception is java.sql.SQLException: Duplicate key or integrity constraint violation message from server: "Duplicate entry 'rick0@foobar.com' for key 2"
java.sql.SQLException: Duplicate key or integrity constraint violation message from server: "Duplicate entry 'rick0@foobar.com' for key 2"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1167)
這個問題找了很久,暈了很久,終于找到了問題的所在。因我在定義數(shù)據(jù)表字段時加了not null unique,而我一次添加N條記錄時的內(nèi)容一樣,主鍵是自動生成的,所以出問題了。
posted on 2005-09-06 10:03
Harryson 閱讀(2302)
評論(0) 編輯 收藏 所屬分類:
Hibernate