In Hibernate JPA; OneToMany, how can I filter the results; as i don't want to delete any data ever

I do not want to perform delete operations in my webapp. Therefore, I save the state of the column in all tables, which is equal to P if the record is deleted. By default, I want to receive records; objects with status = P should not be selected; that is, additional where the condition must be met ... where status = A; or status! = P.

What is the best way to achieve this using annotations? I can, of course, write a manual request ..

For example: the My User class may have several children. How can we implement so that user.getChilds () does not return children with a status like P

User.java @OneToMany( mappedBy = "usr", targetEntity = Child.class, fetch = FetchType.EAGER, cascade = CascadeType.ALL ) @OrderBy( "fullName ASC" ) List<Child> childs; Child.java: @ManyToOne @JoinColumn User usr; 
+4
source share
1 answer

Use Hibernate filters or optional where the clause . The filter can be activated and parameterized at runtime, while the where clause cannot. But they are both used to apply extra where where to the constant set.

+6
source

Source: https://habr.com/ru/post/1414603/


All Articles