Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
3.1
Mapping documents:
Code:
<class name="stricent.abc.datastorage.orm.Project" table="project">
<id name="id" type="long" unsaved-value="0">
<column name="project_id" sql-type="integer" not-null="true"/>
<generator class="native"/>
</id>
<property name="projectName" not-null="true" unique="true" />
<set name="items" table="project_items" lazy="false" inverse="false" cascade="all">
<key column="project_id" />
<!--<many-to-many column="item_id" unique="true" class="stricent.abc.datastorage.orm.Item"/>-->
<one-to-many class="stricent.abc.datastorage.orm.Item"/>
</set>
</class>
<class name="stricent.abc.datastorage.orm.Item" table="item">
<id name="id" type="long" unsaved-value="0">
<column name="item_id" sql-type="integer" not-null="true"/>
<generator class="native"/>
</id>
<property name="createFolder"/>
<property name="itemStatus" not-null="true"/>
<property name="studyStatus" not-null="true"/>
<property name="urgent"/>
<joined-subclass name="stricent.abc.datastorage.orm.ScientificAdviceItem" extends="stricent.abc.datastorage.orm.Item" table="item_sci_adv" >
<key column="item_id"/>
<property name="type" not-null="true" />
<property name="meetingDate"/>
<property name="registrationDeadline"/>
<property name="informationDeadline"/>
<property name="itemNumber"/>
</joined-subclass>
etc etc
</class>
Code between sessionFactory.openSession() and session.close():Code:
M1Item clone = m11.clone();
log.debug(clone + " " + m11 + " " + clone.hashCode() + " " + m11.hashCode() + " " + clone.equals(m11)); //this states that the two object are equals
log.debug("Contains: " + proj.getItems().contains(m11)); //returns false
for (Item item : proj.getItems()) {
if (item.equals(m11)) {
log.debug("Custom contains: returned true"); //this row does print
}
}
boolean removed = ((Set) proj.getItems()).remove(m11);
log.debug("Removed: " + removed); //nothing is removed
log.debug("Proj items size: " + proj.getItems().size()); //still same size
dataStorage.updateObject(proj); //going fine
dataStorage.deleteObject(m11); //throws exception
Full stack trace of any exception that occurs:Code:
org.hibernate.ObjectDeletedException: deleted object would be re-saved by cascade (remove deleted object from associations): [stricent.abc.datastorage.orm.M1Item#22975]
at org.hibernate.impl.SessionImpl.forceFlush(SessionImpl.java:1021)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:168)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:98)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:529)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:521)
at org.hibernate.engine.CascadingAction$1.cascade(CascadingAction.java:134)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:157)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:290)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:185)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:160)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
at org.hibernate.event.def.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:130)
at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:121)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1007)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:354)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at stricent.abc.datastorage.DataStorage.commitTransaction(DataStorage.java:149)
at stricent.abc.datastorage.DataStorage.deleteObject(DataStorage.java:245)
at stricent.abc.datastorage._TestDataStorage.testDelete(_TestDataStorage.java:239)
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 junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at junit.textui.TestRunner.doRun(TestRunner.java:116)
at com.intellij.rt.execution.junit2.IdeaJUnitAgent.doRun(IdeaJUnitAgent.java:57)
at junit.textui.TestRunner.start(TestRunner.java:172)
at com.intellij.rt.execution.junit.TextTestRunner2.startRunnerWithArgs(TextTestRunner2.java:23)
at com.intellij.rt.execution.junit2.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:97)
at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)
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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
Name and version of the database you are using:
Oracle 9i
The codes says it. I have a set. It says it does not contain an object, but it does. I try to remove it but it is not removed. I update the object with the set (this goes fine but nothing has changed). I try to delete the object that I tried to remove.... errr...
What am I doing that I was not supposed to? To me, it seems that PersistentSet does not implement Set correctly but I guess it just me. :-)