Skip to content

Files

Latest commit

 

History

History

HibernateSpringBootSoftDeletesSpringStyle

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

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 abstract class, BaseEntity, annotated with @MappedSuperclass
  • in BaseEntity define a flag-field named deleted (default this field to false or in other words, not deleted)
  • every entity that wants to take advantage of soft deletes should extend the BaseEntity classs
  • write a @NoRepositoryBean named SoftDeleteRepository and extend JpaRepository
  • override and implement the needed methods that provide the logic for soft deletes (check out the source code)
  • repositories of entities should extend SoftDeleteRepository

Output example:


If you need a deep dive into the performance recipes exposed in this repository then I am sure that you will love my book "Spring Boot Persistence Best Practices"If you need a hand of tips and illustrations of 100+ Java persistence performance issues then "Java Persistence Performance Illustrated Guide" is for you.