Add support for soft deletes [DATAJPA-307] #676
Referenced from: pull request #48
74 votes, 64 watchers
The text was updated successfully, but these errors were encountered:
Dev Naruka commented
I saw that there is some activity towards implementing soft delete using the query augmentation.
Generally a delete has the following impacts:
And soft delete changes the delete action in the following ways:
So, the infrastructure is already there to do the first two points. Have anybody planned SOFT-DELETE Cascade yet? or more generically infrastructure level support for providing an opportunity to query augmentors to augment query during a CASCADE.
If not, then I would like to volunteer for the same.
However, I have already started on Querydsl Soft Delete filters and would be doing the native query augmentation also, but it would be great has some foresight on the cascade mechanism
Rob Maskell commented
I'd like to test this and tried adding the following to my build.gradle
ext['spring-data.commons.version'] = '1.11.0.DATACMNS-293-SNAPSHOT' ext['spring-data.jpa.version'] = '1.9.0.DATAJPA-307-SNAPSHOT'
but it didn't pull in the correct dependencies, I'm using the 1.3 milestone release of spring boot, what did I do wrong?
Jack Matthews commented
Can I just suggest something else that would be great with this feature, that is the ability to query all records in certain situations. In my case I have a requirement to make records active/inactive (which for all intensive purposes inactive=deleted). However, the user has the ability to reactivate (undelete) a records at any time from a management screen. So everywhere in the application the soft delete filter should filter the inactive records out of the queries except on a single administration screen whereby the user can toggle the active flag on the record.
I am thinking an annotation on the spring-data-jpa query might be the way to go.
@IncludeDeleted <---------------- This annotation could disable the soft delete filtering @Query('select from account') private List<Account> findAllIncludingDeleted();
Tasos Zervos commented
To add to the last comment.
This is probably one of these low priority (and probably tricky) features.
But I'd like you to make a decision whether you are seriously planning to support it or if not state that you won't. Just that.
People, groups, companies can then make their minds whether they really need this feature (and do something about it, like the last comment suggested) or come up with different ways to achieve the same goals as with soft deletes
Once one starts to look into this in detail it becomes really complex.
You can implement this using native Hibernate features though. Search for "Hibernate soft deletes" in your preferred search engine.
See for reference: spring-projects/spring-data-commons#766 (comment)
We might also consider building an example how this could be achieved in order to explore the limitations. See #2163