File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes soft delete functionality Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "soft delete functionality" Watch "soft delete functionality" New topic
Author

soft delete functionality

Nrapendra Sharma
Ranch Hand

Joined: Jun 16, 2008
Posts: 31
Hi,
What are the best practices for soft delete a record in database using hibernate.
One simple way is to maintain a flag (say: isDeleted).
Is there any other better aproach ??

Regards,
Nrapendra Sharma
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

My approach has usually been to create some type of 'active' flag for a record that gets set when it is soft deleted. Then, at regular intervals, the records with the soft delete active flag are dealt with, either deleted or moved to a history table or something.

-Cameron McKenzie
Nrapendra Sharma
Ranch Hand

Joined: Jun 16, 2008
Posts: 31
Thanks for the response.
I think maintaing flag will work fine as you said.
Now i have many search queries on this entity..
how can i exclude the records with deleted flag true, with least change of code ??
Hari Dhanakoti
Ranch Hand

Joined: Jan 07, 2008
Posts: 74
Hi Sharma,
Have you tried the same and attained the solution? How did you handle the same for the Many-to-many relationship.
Please do revert ASAP


Regards,
Hari
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not sure I follow how the logic changes based on the type of association? Is your question more about a specific JPA implementation?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Hari Dhanakoti
Ranch Hand

Joined: Jan 07, 2008
Posts: 74
Any of the implementation JPA or the other.
I face the same situation.

I have a master table where i have a separate entity the reference table doesn't have the entity class. I have used the @SQLDelete annotation to restrict the delete operation into update operation on the master table but the reference table record gets deleted automatically when entityManager.remove() is called.

Is there is any possible way to restrict the delete operation performed on the reference table which doesn't have an entity class.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Don't cascade deletes, or implement @SQLDelete method on all entities that participate in soft deletes.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: soft delete functionality