我創建了一個Grails應用程序並將其部署到Tomcat服務器。我已經將Grails應用程序配置爲使用外部MySQL數據庫。在啓動Tomcat服務器並部署應用程序(並創建數據庫模式)之後,我運行一個腳本,將關係數據從現有數據庫中的多個表傳輸到由Grails應用程序生成的新數據庫。Grails MySQLIntegrityConstraintViolationException拋出
腳本運行沒有問題,並且INSERT期間沒有數據庫錯誤。
插入後,我使用我的Grails應用程序查看所有現有數據,沒有任何問題。
但是,如果我停止Tomcat服務器並重新啓動它,則會出現問題。我面臨着catalina.out中出現以下錯誤:
2013-01-15 00:43:37,820 [pool-2-thread-1] ERROR util.JDBCExceptionReporter - Duplicate entry '1-2' for key 'PRIMARY'
2013-01-15 00:43:37,826 [pool-2-thread-1] ERROR events.PatchedDefaultFlushEventListener - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
at java.util.concurrent.FutureTask.run(FutureTask.java:166)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
Caused by: java.sql.BatchUpdateException: Duplicate entry '1-2' for key 'PRIMARY'
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:2024)
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1449)
at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:297)
... 6 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1-2' for key 'PRIMARY'
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1039)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2625)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2415)
at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1976)
... 9 more
我對這個錯誤感到困惑,因爲如果存在重複的數據,怎麼會信息已成功插入擺在首位?
謝謝!
看來批處理數據遷移腳本再次執行了嗎? – coderLMN