0

我想知道是否有办法为休眠析取添加条件?

例子

    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);

谢谢

4

1 回答 1

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);
于 2012-07-25T14:51:24.440 回答