How To Implement Soft Deletes Via SoftDeleteRepository In Spring Boot Application
Note: Spring Data built-in support for soft deletes is discussed in DATAJPA-307.
Description: This application is an example of implementing soft deletes in Spring Data style via a repository named, SoftDeleteRepository.
Key points:
- define an
abstractclass,BaseEntity, annotated with@MappedSuperclass - in
BaseEntitydefine a flag-field nameddeleted(default this field tofalseor in other words, not deleted) - every entity that wants to take advantage of soft deletes should extend the
BaseEntityclasss - write a
@NoRepositoryBeannamedSoftDeleteRepositoryand extendJpaRepository - override and implement the needed methods that provide the logic for soft deletes (check out the source code)
- repositories of entities should extend
SoftDeleteRepository


