Skip to content

yuequan1997/jpa-soft-delete-spring-boot-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What does this do?

A simple JPA spring-boot-starter to add conventions for flagging records as discarded.

Usage

Add a maven dependency to your pom.xml

<dependency>
  <groupId>org.yuequan</groupId>
  <artifactId>jpa-soft-delete-spring-boot-starter</artifactId>
  <version>1.0.0.RELEASE</version>
</dependency>

Add @EnableJpaSoftDeleteRepositories annotation to your in application class

@SpringBootApplication
@EnableJpaSoftDeleteRepositories
public class JpaSoftDeleteSpringBootStarterApplication {
    public static void main(String[] args){
        SpringApplication.run(JpaSoftDeleteSpringBootStarterApplication.class, args);
    }
}

Add @SoftDelete annotation to your in repository class

@SoftDelete
public interface UserRepository extends JpaRepository<T, ID> {
    
}

Add removed_at column to your table and add removedAt to your entity, will support customization in the next release

userRepository.delete(user);   
// update users set removed_at=? where id=1

userRepository.findById(user.getId())
// select .... from users user0_ where user0_.id=.. and (user0_.removed_at is null)
    
userRepository.findAll(PageRequest.of(0, count))
// select .... from users user0_ where user0_.removed_at is null limit ?

About

Soft deletes for Spring Data Jpa

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages