본문 바로가기
Hibernate

hibernate criteria query 조건문

by 자바초보자 2016. 2. 23.
728x90
(((A='X') and (B in('X',Y))) or ((A='Y') and (B='Z')))
Criteria criteria = getSession().createCriteria(clazz);
Criterion rest1= Restrictions.and(Restrictions.eq("A", "X"),
Restrictions.in("B", Arrays.asList("X","Y")));
Criterion rest2= Restrictions.and(Restrictions.eq("A", "Y"),
Restrictions.eq("B", "Z"));
criteria.add(Restrictions.or(rest1, rest2));

 

 

(A or B or C or ....)

if(vo.getSeSeqs() != null && vo.getSeSeqs().length > 0){
   Disjunction disc = Restrictions.disjunction();
   for(Integer seSeq : vo.getSeSeqs()){
    disc.add(Restrictions.like("goodsSeCodes", "%["+seSeq+"]%"));
   }
   criteria.add(disc);
  }

 

 

 


 

 

    select
        this_.GOODS_RCORD_SEQ as y0_
    from
        S_SOPMAL_GOODS_RCORD this_
    where
        this_.GOODS_RCORD_SEQ = (
            select
                b_.GOODS_RCORD_SEQ as y0_
            from
                S_SOPMAL_GOODS_OPTN b_
            where
                b_.GOODS_RCORD_SEQ=this_.GOODS_RCORD_SEQ
                and b_.GOODS_OPTN_NM like ?
            group by
                b_.GOODS_RCORD_SEQ
        )

 

 

  Criteria criteria = getCurrentSession().createCriteria(SopmalGoodsRcordModel.class, "a");
  ProjectionList projectionList = Projections.projectionList();
  //projectionList.add(Projections.property("siteId"), "siteId");
  projectionList.add(Projections.property("goodsRcordSeq"), "goodsRcordSeq");
  criteria.setProjection(projectionList).setResultTransformer(CustomTransformers.ALIAS_TO_ENTITY_MAP);
  
  DetachedCriteria sub = DetachedCriteria.forClass(SopmalGoodsOptnModel.class, "b");
  
  sub.add(Restrictions.eqProperty("b.goodsRcordSeq", "a.goodsRcordSeq"));
  sub.add(Restrictions.like("b.goodsOptnNm", "%소고기%"));
  sub.setProjection(Projections.groupProperty("b.goodsRcordSeq"));
  
  criteria.add(Subqueries.propertyEq("a.goodsRcordSeq", sub));

728x90