hibernate 模糊查询及not in子查询

来源:互联网 发布:武汉数据分析 编辑:程序博客网 时间:2024/05/15 08:11

代码如下

Query query1=this.getSession().createSQLQuery(" select p.smallClassId as smallClassId,p.id as id,p.name as name,p.thumbNail as thumbNail,p.marketPrice as marketPrice,p.memberPrice as memberPrice from product p  where  p.name like ? and p.smallClassId= ? and p.valid=true  and p.id not in (select sp.productId from  special_product  sp where  sp.specialId =? and sp.valid=true)")    .addScalar("id",StandardBasicTypes.LONG)      .addScalar("thumbNail")      .addScalar("marketPrice")      .addScalar("memberPrice")              .addScalar("name")            .addScalar("smallClassId",StandardBasicTypes.LONG)            .setResultTransformer(Transformers.aliasToBean(SpecialVo.class));   query1.setParameter(0, "%"+name+"%");  query1.setParameter(1, smallClassId);  query1.setParameter(2, id);  List<SpecialVo> specialVos1=query1.list();    for (SpecialVo s:specialVos1){     s.setIsSpecial(false);     s.setQuantity(0);   }  specialVos.addAll(specialVos1);


本文出自 “点滴积累” 博客,请务必保留此出处http://tianxingzhe.blog.51cto.com/3390077/1678159

0 0
原创粉丝点击