want to delete child, but not childs references to other objects
Let's say i have three objects: user, box, products
the user has got a box, the box has references to different products that the user has got in his box.
the user can basically decide which products he wants to have in his box.
if i delete the user开发者_开发百科, i want the box to be deleted as well, but i do NOT want the products to be deleted.
how can i go about doing this in hibernate?
my attempt was this:
in the User.hbm.xml, have an entry
<many-to-one name="theBox" column="BOX"
class="com.example.Box"
unique="true" cascade="all"/>
however, that seems to want delete the products as well...
dont use cascade="all"
. All means "All". you can use save, update
. Check out the documentation on transitive persistance.
From that documentation, you might want to try cascade="persist,merge,save-update".
精彩评论