Used Hibernate version is 3.02
I have a simple parent-child relationship defined through <set...>
mapping (child uses many-to-one)
----------- mapping snippet from ParentClass ------------------
<set
name="childClasses"
lazy="true"
cascade="none"
sort="unsorted"
inverse="true"
>
<!-- I also tried with out "inverse"- same results -->
<key
column="parentId"
foreign-key="parentIdFk"
/>
<one-to-many
class="mypackage.ChildClass"
/>
</set>
----------- mapping snippet from ChildClass ------------------
<many-to-one
name="parentClass"
class="mypackage.ParentClass"
cascade="none"
outer-join="false"
>
<column
name="parentId"
not-null="false"
/>
</many-to-one>
---------------------------------------------------------------
All seems to be working for as long as I do not try to remove
a child from parent (child gets NULL id and is being updated in the
database by Hibernate)
-- I use opened session, I save both parent and child and I flash() --
However, when I load the parent class and look for its children
I still see the child I have removed :(
(I load Parent immediately after saving them both in the same
test method so that session and cache are still open/active)
I have done some testing and what I have found is this:
Child gets updated OK because I explilistly set its parentId to NULL
But when I try to remove child from the list - nothing happends.
I looked at run-time instance of my shild list and it is
org.hibernate.collection.PersistentSet and operations like
remove(), contains() yield no results: the child object is not found
and does not get removed.
I gone further: I do explisitly test if the same child exists in the
list by iterating through all children and I find it (child.equals() and
child.hashCode() - both yield TRUE). I have even tried to set my child
so that it references the one in the list directly
(child == childFromList is TRUE)
Still no removal.
I have lost my mind....
I have tried to use source from Hibernate but this requires so many other
libraries to be linked even at compile time that I gave up on that.
Any help?
Thanks.
Nik
|