|
Hi
I have a question regarding cascading styles when used for unidirectional associations. Say, I have object X and object Y such that X has a one-to-many association with Y, its unidirectional, so Y doesnt have a back reference to X object. That gives me a table for X object and a table for object Y with a column for x_id, right.
If I already have an instance x1 for Object X saved in the database. Now, I want to add a new y1 instance of Object Y to x1. The only way I got it working was to:
(1) get the x1 instance from the database.
(2) create y1 and add it to x1 {x1.add(y1)}
(3) save(y1)
(4) update(x1)
Can this be achieved using any of the cascade styles. I tried using both save and update but that doesnt work. With cascade "save-update" if I update the x1 after adding y1 to it, hibernate tries to update a y1 object that doesnt even exist and if I save x1 after adding y1 to it, hibernate obvioulsy tries to resave the x1 object to the database.
If I cannot do what I am doing with cascade styles, is there any other way besides the one I did, to achieve the same thing?
Thanks a lot,
Neha.
|