我创建了一个Grails应用程序并将其部署到Tomcat服务器。我已将Grails应用程序配置为使用外部MySQL数据库。在我启动Tomcat服务器并部署应用程序(并创建数据库模式)之后,我运行一个脚本,将来自现有数据库中多个表的关系数据传输到Grails应用程序生成的新数据库。
脚本运行没有问题,在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 :(得分:0)
检查您的BootStrap.groovy文件并检查您是否不在存在的数据库中插入任何内容
实施例: def adminRole = Role.findByAuthority(“ROLE_ADMIN”)?:new role(authority:“ROLE_ADMIN”)。save(failOnError:true)