In Hibernate JPA; OneToMany how can I filter results; as I do not want to delete any data ever
hibernate, jpa
Solution
Use Hibernate filters, or an additional where clause. A filter can be activated and parameterized at runtime, whereas a where clause can't. But they're both used to apply an additional where clause to a persistent collection.
Problem
I do not want to perform delete operations in my webapp. Hence I keep a column Status in all tables which is equal to P if record is deleted. By default I want that when records are fetched; entities with status = P should not be fetched; i.e. an additional where clause should happen... where status = A ; or status != P. What is the best way to achieve it using annotations ? I can surely write a manual query.. For example :My User class can have multiple childs. How can we implement so that user.getChilds() does not return childs with status as 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; ```