在QBE上使用析取

时间:2015-10-16 19:44:54

标签: hibernate criteria restrictions query-by-example

是否可以在标准示例中使用析取?

我尝试使用Example过滤一些数据。

    Criteria critFatura = ((Session)em.getDelegate()).createCriteria(Fatura.class);
    critFatura.add(Example.create(fatura).enableLike(MatchMode.ANYWHERE));

    critFatura.setFetchMode("tipoPublicidade", FetchMode.JOIN);
    critFatura.createCriteria("situacao")
            .add(Example.create(fatura.getSituacao()));

    critFatura.createCriteria("aprovacaoProducao", "aprovacaoProducao", JoinType.LEFT_OUTER_JOIN)
            .createCriteria("aprovacaoProducao.agencia", "agencia", JoinType.LEFT_OUTER_JOIN)
            .add(Example.create(agencia));

    critFatura.createCriteria("pedidoInsercao", "pedidoInsercao", JoinType.LEFT_OUTER_JOIN)
            .createAlias("pedidoInsercao.planoMidia", "planoMidia", JoinType.LEFT_OUTER_JOIN)
            .createAlias("planoMidia.doac", "doac", JoinType.LEFT_OUTER_JOIN);

    critFatura.createCriteria("memorando", "memorando", JoinType.LEFT_OUTER_JOIN);

    Criteria mCampanha=critFatura.createCriteria("memorando.campanha", "campanha2", JoinType.LEFT_OUTER_JOIN)
            .add(Example.create(campanha));
    Criteria dCampanha= critFatura.createCriteria("doac.campanha", "campanha", JoinType.LEFT_OUTER_JOIN)
            .add(Example.create(campanha));

我希望“memorando.campanha”和“doac.campanha”属性介于某个或条件之间。

但是示例总是把它们放在And条件下。

如何将这两个例子放在分离上?

1 个答案:

答案 0 :(得分:0)

criteria.add(Restrictions.or(criterion1,criterion2))

其中criterion1 = Restrictions.eq(memorando.campanha,“campanha2”);