-
1. Re: How to function soft delete
boomerbrian.brian.abston.featurenotbug.com May 25, 2010 2:18 PM (in response to vasukihn)I blogged about soft deletes a couple of months ago. This shows you how to do it.
-
2. Re: How to function soft delete
vasukihn May 25, 2010 2:36 PM (in response to vasukihn)Hello Brain,
Thanks for replying.
I read through your blog. After reading your posting i got to know that we can make use of hibernate annotations for soft delete. I did the same changes as you have explained in my java file. But i'm getting many errors. So i thought i should also change in *.xhtml file. If so, what changes i need to do? please explain me detail. -
3. Re: How to function soft delete
vasukihn May 25, 2010 2:39 PM (in response to vasukihn)Sorry Brian. i misspelled your name. Please let me know the solution.
-
4. Re: How to function soft delete
boomerbrian.brian.abston.featurenotbug.com May 25, 2010 3:09 PM (in response to vasukihn)You shouldn't have to change anything in the view. The soft delete is handled by Hibernate. The annotations should be all you need. The view and controller layer knows nothing about it.
Post your code and errors in this thread.
-
5. Re: How to function soft delete
vasukihn May 26, 2010 5:56 AM (in response to vasukihn)Hello Brian,
Thanks for writing the blog. Earlier i followed the blog and made the same changes in my model.
The reason why I was getting the error message was, while writing the query
(@SQLDelete(sql="UPDATE site SET active= '0' WHERE locationid = ?"))
I mistyped the column name (locationid )so it was saying "Coudln't identify the column in the database".
Now i changed the column name and soft delete is happening.
Now i have another question. How to soft delete the child table data while deleting the parent table data?
Example:
Site is a parent table and Location is the child table for it. When i do soft delete for a row in site table the associated row in the location table must also be inactivated.
So please guide me how to do this.
Thanks
Vasuki -
6. Re: How to function soft delete
boomerbrian.brian.abston.featurenotbug.com May 26, 2010 2:33 PM (in response to vasukihn)Setup your Location Entity to soft delete just like you did with the Site Entity. Then you will need to set the Location relationship in the Site Entity to cascade delete. Here is an example. Look at the Hibernate docs for all of the cascade options. Now when you delete the Site the Location should be deleted as well.
@OneToMany(fetch = FetchType.LAZY, mappedBy = "site", cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}) public Set<Location> getLocations() { return this.Locations; }
-
7. Re: How to function soft delete
vasukihn May 28, 2010 7:15 AM (in response to vasukihn)Hello Brian,
Thanks for the solution. It is working like a charm.
-
8. Re: How to function soft delete
iravhari Sep 29, 2010 7:21 AM (in response to vasukihn)Thanks for the valuable update Brain.
Hi vasuki,
Have you tried the same soft delete for ManyToMany relationship where the reference table doesn't have an entity?What needs to be modified on the code