if(StringUtils.isNotBlank(qo.getOwnerShop())){ //cr.add(Restrictions.eq("quanType.ownerShop", qo.getOwnerShop())); String sql = String.format("EXISTS (SELECT * from q_type g where this_.quanType_ID=g.ID and ownerShop='%s' )", qo.getOwnerShop() ); cr.add(Restrictions.sqlRestriction( sql)); }