org.hibernate.exception.ConstraintViolationException: couldnotexecutestatementatorg.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:59) atorg.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) atorg.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) atorg.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95) atorg.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:207) atorg.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45) atorg.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1313) atorg.hibernate.action.internal.CollectionRecreateAction.execute(CollectionRecreateAction.java:50) atorg.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:560) atorg.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:434) atorg.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337) atorg.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39) atorg.hibernate.internal.SessionImpl.flush(SessionImpl.java:1282) atorg.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:465) atorg.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2963) atorg.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2339) atorg.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:485) atorg.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:147) atorg.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38) atorg.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:231) atorg.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:65) attop.simba.dao.HibernateMMDao.fn01(HibernateMMDao.java:52) atsun.reflect.NativeMethodAccessorImpl.invoke0(NativeMethod) atsun.reflect.NativeMethodAccessorImpl.invoke(UnknownSource) atsun.reflect.DelegatingMethodAccessorImpl.invoke(UnknownSource) atjava.lang.reflect.Method.invoke(UnknownSource) atorg.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50) atorg.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) atorg.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47) atorg.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) atorg.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325) atorg.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78) atorg.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57) atorg.junit.runners.ParentRunner$3.run(ParentRunner.java:290) atorg.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71) atorg.junit.runners.ParentRunner.runChildren(ParentRunner.java:288) atorg.junit.runners.ParentRunner.access$000(ParentRunner.java:58) atorg.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268) atorg.junit.runners.ParentRunner.run(ParentRunner.java:363) atorg.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86) atorg.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) atorg.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Causedby: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicateentry'1-1'forkey'PRIMARY'atsun.reflect.NativeConstructorAccessorImpl.newInstance0(NativeMethod) atsun.reflect.NativeConstructorAccessorImpl.newInstance(UnknownSource) atsun.reflect.DelegatingConstructorAccessorImpl.newInstance(UnknownSource) atjava.lang.reflect.Constructor.newInstance(UnknownSource) atcom.mysql.jdbc.Util.handleNewInstance(Util.java:404) atcom.mysql.jdbc.Util.getInstance(Util.java:387) atcom.mysql.jdbc.SQLError.createSQLException(SQLError.java:934) atcom.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3966) atcom.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3902) atcom.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2526) atcom.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2673) atcom.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549) atcom.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861) atcom.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073) atcom.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009) atcom.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5098) atcom.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994) atcom.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:147) atorg.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:204) ... 40more
解决方案:
双向关联,一定要一方放弃主键维护。在其中一方标签添加inverse=“true”