My problem is I have a form where I display a blog with all of its items. The user can update/delete and create new items in the form all in one action (HTTP POST)
So for example, lets say Blog with name="Hibernate" has 3 blog items, item1, item2 and item3
The database is queried to fetch the blog and its items initially and the blog is evicted from the session so that a new blog object with same id can be attached later.
That information is shown in a HTML form to the user, and the user takes the following actions in the form.
2. updates item2 (changes the text for example)
3. And created a new item4. (using a dynamically generated required form input elements) and submits the form.
When the form is submitted, I am able to save the updated item2 and the new item4 using saveOrUpdate() on the new Blog object constructed from the browser fields.
However I am not able to have the item1 deleted automatically.
One way (expensive way) to accomplish the deletion of item1 is to read the Blog from db and check for any missing items in the item array that came from the browser.
Is that the only way to achieve this? Does hibernate provide any magic to solve this elegantly?