在测试hibernate时出现了如下异常:
[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)
这个问题找了很久,晕了很久,终于找到了问题的所在。因我在定义数据表字段时加了not null unique,而我一次添加N条记录时的内容一样,主键是自动生成的,所以出问题了。
posted on 2005-09-06 10:03
Harryson 阅读(2296)
评论(0) 编辑 收藏 所属分类:
Hibernate