开发者

BatchUpdateException - MySQL Error 'Duplicate entry' - which key/constraint has been violated?

开发者 https://www.devze.com 2023-02-03 18:05 出处:网络
The combo mysql/hibernate is creating exception stack traces like Caused by: java.sql.BatchUpdateException: Duplicate entry \'7872551600-B1310955127\' for key 2

The combo mysql/hibernate is creating exception stack traces like

Caused by: java.sql.BatchUpdateException: Duplicate entry '7872551600-B1310955127' for key 2

at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:652) at org.jboss.resource.adapter.jdbc.WrappedStatement.executeBatch(WrappedStatement.java:519) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268) ... 51 more

Now what's happening is obvious. There's a table with a constraint (unique key), and this constraint 开发者_Go百科has been violated.

But all the exception says that some key '2' has been violated. Is there a way to make mysql print out which constraint has been violated? or at least on which table?

Thanks holger


Key 2 is the second index on the table. If you have a primary key, key 2 is the first index after that.

I can't tell you which table it is, but once you figure that out if you run SHOW CREATE TABLE on that table the second index it lists is the one that was violated.

0

精彩评论

暂无评论...
验证码 换一张
取 消