JohnSmith
JohnSmith

Reputation: 4688

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...

Upvotes: 1

Views: 115

Answers (1)

hvgotcodes
hvgotcodes

Reputation: 120188

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".

Upvotes: 1

Related Questions