2013-01-15 48 views
0

我创建了一个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 

我对这个错误感到困惑,因为如果存在重复的数据,怎么会信息已成功插入摆在首位?

谢谢!

+0

看来批处理数据迁移脚本再次执行了吗? – coderLMN

回答

0

检查BootStrap.groovy中的文件,并检查客人不愿意在存在

示例数据库中插入什么: 高清adminRole = Role.findByAuthority(“ROLE_ADMIN”):新角色(权限:“ ROLE_ADMIN“)。save(failOnError:true)

相关问题