Is there any way in OQL (Object Query Language) to select an object, by filtering out all objects matching a certain property?
To access Category
objects recursively I just retrieve the root-Category. Later I access its children-property through FetchType.EAGER
.
Now, when I delete a Category, I in reality don't delete it, but set the deleted-property to true. This works well with the modified/deleted category, but when I access the children-property, I still get the deleted Category objects.
My current OQL-Select to get the root-Category looks like this:
SELECT c FROM Category c WHERE c.name = 'Root'
Is there any way to filter out the all the Category-objects that have Category.deleted = true
? I mean recursively, so that I will not find deleted-true-Categories within the children-property?
The entity looks like this:
@Entity
@NamedQueries({
@NamedQuery(name = Category.FIND_CATEGORY_ROOT,
query = "SELECT c FROM Category c WHERE c.name = 'Root'")
})
public class Category implements Serializable {
private static final long serialVersionUID = 1L;
private static final String PREFIX = "Category.";
public static final String FIND_CATEGORY_ROOT = PREFIX + "findCategoryRoot";
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private boolean deleted;
@OneToMany(fetch = FetchType.EAGER)
private List<Category> children;
// More code here
}