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));
'Hibernate' 카테고리의 다른 글
hibernate Could not find setter (모델 ProjectionList 오류) (1) | 2016.06.02 |
---|---|
select, save update 시 디비 특정 function을 호출해야될경우 (0) | 2016.04.06 |
onetomany order by 정렬 순서 문제 (0) | 2016.02.23 |
하이버네이트 모든 테이블명 조회 (0) | 2015.11.23 |