浏览 2059 次
锁定老帖子 主题:诚心请教一HQL的写法或映射方法.急...
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-12-21
标准SQL是这样: select a.BRANDID,a.PICURL ,a.BRAND_CH ,a.SORT ,count(b.PRODUCTID) as counts from BRAND a left outer join PRODUCT b on a.BRANDID =b.BRANDID and b.Auditstatus='1' where a.STATUSFLAG = 0 group by a.BRANDID, a.PICURL, a.BRAND_CH, a.SORT order by a.SORT 调整前的代码: StringBuffer sql = new StringBuffer(); sql.append("select new com.kmi.terminal.memory.model.view.ViewBrand(a.brandid,"); sql.append("a.picurl,a.brandCh,a.sort,count(b.productid)) from ").append(TABLE_NAME); sql.append(" a left join a.products b "); sql.append(" where a.statusflag=0 "); sql.append(" group by a.brandid,a.picurl,a.brandCh,a.sort order by a.sort"); 调整后的代码: StringBuffer sql = new StringBuffer(); sql.append("select new com.kmi.terminal.memory.model.view.ViewBrand(a.brandid,"); sql.append("a.picurl,a.brandCh,a.sort,count(b.productid)) from ").append(TABLE_NAME); sql.append(" a left join a.products b "); sql.append(" and b.auditstatus='1' where a.statusflag=0 "); sql.append(" group by a.brandid,a.picurl,a.brandCh,a.sort order by a.sort"); 具体变化在这一行: sql.append(" and b.auditstatus='1' where a.statusflag=0 "); 我本来是想Hibernate解析后自动就加上where前的and 条件,结果确不是往想象的方向发展 我想实现和标准SQL相同效果的一个HQL要如何写,或在*.hbm.xml中要如何修改.烦请达人告知 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2007-12-21
不要用and 用with
left join cat.kittens as kitten with kitten.bodyWeight > 10.0 |
|
返回顶楼 | |
发表时间:2007-12-21
red008 写道 不要用and 用with
left join cat.kittens as kitten with kitten.bodyWeight > 10.0 谢谢,再感谢,完全正解.... |
|
返回顶楼 | |