我想知道是否有办法为休眠分离添加条件?
实施例
Criterion creator;
if(securityService.hasRole(RoleConstants.ROLE_CREATOR) {
creator = Restrictions.conjunction()
.add(Restrictions.eq("creator", this.userInfo.getUser()))
.add(Restrictions.eq("currentState.id", DatabaseConstants.STATE_DRAFT));
}
Criterion completeCondition = Restrictions.disjunction().add(creator)
.add(authorizer)
.add(assessor);
由于
答案 0 :(得分:0)
我想出了如何使用具有析取的条件。
Disjunction dis = Restrictions.disjunction();
if(this.securityService.hasRole(RoleConstants.ROLE_AUTHORIZER)) {
dis.add(Restrictions.eq("currentState.id", DatabaseConstants.STATE_AUTHORIZER_REVIEW));
}
if(this.securityService.hasRole(RoleConstants.ROLE_ASSIGNOR)) {
dis.add(Restrictions.eq("currentState.id", DatabaseConstants.STATE_ASSIGNOR_REVIEW));
}
if(this.securityService.hasRole(RoleConstants.ROLE_ASSESSOR)) {
dis.add(Restrictions.eq("currentState.id", DatabaseConstants.STATE_ASSESSOR_REVIEW));
}
Criteria criteriaStatic = this.session.createCriteria(PurchaseRequest.class)
.add(Restrictions.isNull("authorizedArchiveDate"))
.add(dis);