Using the caveatemptor app as an example I can save fine.
However when I delete an object (using similar code from your test case)
Code:
Long drugId = new Long(354);
tx = session.beginTransaction();
ReportedDrug drugToDel = (ReportedDrug)session.get(ReportedDrug.class, drugId);
drugToDel.getDrugEvents().clear();
tx.commit();
session.close();
Drug has one-to-many with DrugEvent
Event has one-to-many with DrugEvent
DrugEventId is composite key class of DrugEvent
I get this error:
net.sf.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): com.roche.dss.extreportdomainmodel.DrugEventId@292, of class: com.roche.dss.extreportdomainmodel.DrugEvent
at net.sf.hibernate.impl.SessionImpl.forceFlush(SessionImpl.java:752)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:730)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1376)
at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:114)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436)
at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:526)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:452)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:482)
at net.sf.hibernate.impl.SessionImpl.preFlushEntities(SessionImpl.java:2673)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2250)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2239)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at com.roche.dss.extreportdomainmodel.FullReportTest.testDeleteDrug(FullReportTest.java:113)
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:324)
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.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)
Not much experience of this on the forum.
Ken