I have two classes ;
User {
private String name;
private Set<Role> roles;
}
Role {
private String name;
private boolean disabled;
}
In my application a user can get multiple roles assigned, these are stored in the Set of roles.
It can occur that a role gets disabled and should no longer viewable by the users.
I am using Hibernate Criteria to query the tables;
Criteria criteria = session.createCriteria(User.class);
criteria.add(Restrictions.eq("name", name));
Is there a way to query the user table and use this query to also ‘hide’ the disabled roles from his/her Set of roles of should I handle this after I ran my query?
Simplest way, you can use @Where annotation. It is Hibernate proprietary annotation and I don’t like proprietary annotations, but it fits your case.
Sorry for the old links, but in the latest manual of Hibernate I don’t find a good explanation for this annotation, though it is still valid.