开发者

hibernate restore deleted entities

开发者 https://www.devze.com 2023-03-03 23:30 出处:网络
Is there a third-party library which add restore deleted entities feature? i need something like Hibernate envers which creates entities and map them to tables at runtime, but a lot simpler! i just ne

Is there a third-party library which add restore deleted entities feature? i need something like Hibernate envers which creates entities and map them to tables at runtime, but a lot simpler! i just need two tables for each entity s开发者_JAVA百科o that when the entity was deleted it would be moved to the other table.


Perhaps a simpler approach is to never allow anything to be deleted from the table. Instead just have a deleted INT(1) DEFAULT 0 column that specifies whether or not a row has been deleted. Then you can easily get a list of all rows/entities that have been deleted, and undelete any/all that you want by just clearing the deleted flag.

The nice thing about such an approach is that it is ORM-agnostic. You can choose any desired lightweight alternative to Hibernate that you like, and they will all play nicely with this kind of technique. The downside is that you have to do a bit of manual work to get the undelete functionality implemented.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号