Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

soft delete functionality

 
Nrapendra Sharma
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ??
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not sure I follow how the logic changes based on the type of association? Is your question more about a specific JPA implementation?
 
Hari Dhanakoti
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't cascade deletes, or implement @SQLDelete method on all entities that participate in soft deletes.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic