Unique constraint under hibernate
Hello,
I'm trying to run a java junit test in Eclipse.
The test first inserts a few rows in different tables.
But it gives an exception with an Oracle message.
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:235)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:297)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:985)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:333)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at com.ericsson.pii.dataaccessor.AccessDaoHibernateImplSpringTest.testAggregateSingleAccesses(AccessDaoHibernateImplSpringTest.java:74)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: java.sql.BatchUpdateException: ORA-00001: unique constraint (PIIUSER_JUNIT.SYS_C009305) violated
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:342)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10698)
at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
... 24 more
Here is the test source code:
Transaction transaction = session.beginTransaction();
Document d1 = ObjectMother.createSimpleDocument("d1", "a", "EN", documentDao);
Document d2 = ObjectMother.createSimpleDocument("d2", "a", "EN", documentDao);
ObjectMother.createAccess(accessDao, d1, DateUtil.createOneSpecificDay(2006, Calendar.AUGUST, 4, 10, 0, 0).getTime());
ObjectMother.createAccess(accessDao, d1, DateUtil.createOneSpecificDay(2006, Calendar.AUGUST, 4, 10, 10, 0).getTime());
ObjectMother.createAccess(accessDao, d1, DateUtil.createOneSpecificDay(2006, Calendar.AUGUST, 5, 10, 10, 0).getTime());
ObjectMother.createAccess(accessDao, d2, DateUtil.createOneSpecificDay(2006, Calendar.AUGUST, 5, 10, 10, 0).getTime());
ObjectMother.createAccess(accessDao, d2, DateUtil.createOneSpecificDay(2006, Calendar.AUGUST, 6, 10, 10, 0).getTime());
transaction.commit();
The exception message points to the transaction.commit();
line.
I'm in the dark and my search light is dying on me..
Stephane