posts - 0, comments - 77, trackbacks - 0, articles - 356
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

关于DetachedCriteria

Posted on 2007-08-08 23:16 semovy 阅读(1316) 评论(0)  编辑  收藏 所属分类: Hibernate

DetachedCriteria detachedCriteria =DetachedCriteria.forClass(UserVO.class)
 //.add(Restrictions.like("username","sz",MatchMode.ANYWHERE));
   .add(org.hibernate.criterion.Expression.disjunction()  //or查询把add放到外面是and查询,MatchMode.ANYWHERE糊查询
        .add(org.hibernate.criterion.Property.forName("username").like("s", MatchMode.ANYWHERE))
        .add(org.hibernate.criterion.Property.forName("password").like("c", MatchMode.ANYWHERE))
        );

 

多对一情况  
DetachedCriteria  zlbdc=DetachedCriteria.forClass(ZlZlxm.class, "zlb");
                     //  .createAlias("zlb.zl", "t")
                        // .setProjection(Property.forName("t.id").count())
                       //.add(Property.forName("t.id").eq(new  Long(1)))
                       org.hibernate.criterion.Projection projection=org.hibernate.criterion.Projections.projectionList()
                                   .add(org.hibernate.criterion.Property.forName("zlb.fdxx"),"id");
                       zlbdc.setProjection(projection);
                                     //zlbdc.createCriteria("zl");//加上这句是内联接(inner join)zl为集合
投影查询,得到一是object[]


  DetachedCriteria  zlbdc=DetachedCriteria.forClass(ZlZlxm.class, "zlb")
  //zlbdc.createCriteria("zl"); //此处为对象
                       .createAlias("zlb.zl", "t") //别名
                       .setProjection(Property.forName("t.id").count())
                       .add(Property.forName("t.id").eq(new  Long(1))); //这里统计的是个数内联接(inner join)
         //zladc.setFetchMode("zla.zlZlxm", org.hibernate.FetchMode.JOIN);//无作用(集合lazy)???,如果not lazy将会是全部查出


只有注册用户登录后才能发表评论。


网站导航: