How to implement a soft delete with Hibernate

preview_player
Показать описание
In some applications, you don’t want to, or you are not allowed to permanently remove a record from the database. But you still need to remove or hide records which are no longer active. One example could be a user account which you want to keep because it is linked to other business objects which are still used.
You have 2 basic options to keep this information in your system. You can either keep an audit log that documents all changes or perform a soft delete that hides the removed records. I will explain the audit log option in another video. Today I want to show you how to implement a soft delete with Hibernate.

If you like this video, please give it a thumbs up and share it with your friends and co-workers.

Like my channel? Subscribe!

Join the free Member Library:

Want to connect with me?
#Hibernate #JPA #Java #SoftDelete
Рекомендации по теме
Комментарии
Автор

Thank you so much! This should come as a built-in feature since most real-world apps don't "DELETE" database records

Peter-bgku
Автор

This is a cool feature, thanks Thorben for sharing it.

richardlanglois
Автор

What if I have i want to soft delete an entity that has other associations like @ManyToOne etc

athanasiosmelandinos
Автор

thanks you very match .
i want to ask about the second video of this tuto when you talking about second way 'auditing'

teckinfodz
Автор

This is such an awesome topic and equally awesome explanation Thorben...!! Just had one question. Is it possible to provide multiple queries in the @SQLDelete annotation? Like e.g. when an entity is being deleted, I want a record to be inserted in an archive table and also I want the state column to be updated in the entity table. Sort of like how triggers used to work in the databases?

rishinjiya
Автор

I need to do a soft delete, but I don't want to delete the jointables, Could you help me?

leandrosaraceno
Автор

Can you override the Where clause? E.g., you want to get all 'DELETED' entities.

FritzFeuerbacher
Автор

Thank you so much! But, what is better approach to handle manytoone when the fk has value 'DELETE'? Sorry my English

tiagoaleffdasilva