码迷,mamicode.com
首页 > Web开发 > 详细

hibernate 模糊查询及not in子查询

时间:2015-07-25 07:16:43      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:hibernate 模糊查询及not in子查询

代码如下

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

hibernate 模糊查询及not in子查询

标签:hibernate 模糊查询及not in子查询

原文地址:http://tianxingzhe.blog.51cto.com/3390077/1678159

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!