Hello,
I have a web application(Hibernate) where users can drag and drop HTML elements like (text field,label, buttons) and save it. I use saveorupdate function.
I have parent-child relationship through one-to-many associations. I am using annotations.
1:m
Page<--Widgets
I am doing
@OneToMany( cascade = {CascadeType.PERSIST, CascadeType.MERGE} )
@Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
My problem,
--Assume user saves 3 widgets(textfield,label, button), it perfectly saves. Now the user loads back the same data and deletes the button and saves, now there is only 2widgets(textfield,label).
The problem is now the button still exists in the database, I was hoping that cascade.DELETE_ORPHAN will deleted the non-referenced record.
so is that my understanding is wrong or this can't be done this way.
So alternative solution i was thinking was
-- delete everything and just do a new save.
so is there is any better solutions?
~Pen
|