I've implemented soft delete in my spring boot application. Which looks something like:
Program.java
public class Program{
//other attributes
private boolean deletedFlag;
//getter setters
}
And in repository of program
entity, I'm firing following query to only return the entities, which has deleted flag false
.
public interface ProgramRepository{
//other methods
Program findByDeletedFlagFalse();
}
So this implementation works perfectly fine. But the problem is, I've an another entity (named 'Major'), in which I've injected list of programs
. So major
entity looks like:
public class Major{
//other fields
List<Program> programs;
//getter setters
}
Now, when I delete program entities, it still appears in the major, even if they are deleted. So basically my response looks like:
"major":{
//other fields
"program": [{
//other fields
"deletedFlag": true
}]
}
But the expected behavior should be like if we delete child entity, parent should not list it. So what am I missing here?
Is there any alternative of implementing soft delete in spring boot? I've already seen this: Hibernate Soft Delete using update Cascade, But it seems like the answer using hibernate instead of Spring data JPA.
I've already seen this: Handling soft-deletes with Spring JPA, but it is more aligned to hibernet solution instead of spring data JPA.