PO
- public class UserPO implements java.io.Serializable {
- /** 用户唯一标识ID */
- private String id;
- /** 状态(在用1停用0) */
- private String userStatus;
- private Set roles = new HashSet();
- ........
- }
- public class RolePOimplements java.io.Serializable {
- /** 角色唯一标识ID */
- private String id;
- /** 角色级别 */
- private Integer roleLevel;
- private Set users = new HashSet(0);
- ........
- }
查询用户userStatus等于1且他的角色Level等于3的用户
- DetachedCriteria criteria = DetachedCriteria.forClass(UserPO.class); // org.hibernate.criterion.DetachedCriteria
- criteria.add(Restrictions.eq("userStatus", "1"))
- .createAlias("roles", "r")
- .add(Restrictions.eq("r.roleLevel", new Integer(3)));
criteria.add(Restrictions.eq("userStatus", "1"))
.createAlias("roles", "r")
.add(Restrictions.eq("r.roleLevel", new Integer(3)));
需要注意的是:
获取User时是获得了roles的全部记录集,而不是经过过滤的记录集,相当于User的id获得的完整实例一样