帮忙将以下sql语句转为hql语句 :
selectdc.*,count(dp.cat_id)asnumfromd_categorydcleftouterjoind_category_productdpon(d...
select dc.*,count(dp.cat_id) as num
from d_category dc left outer join d_category_product dp on(dc.id=dp.cat_id)
where dc.parent_id = 2
group by dc.id
以上是sql语句,其中d_category对应的pojo为DCategory,d_category_product
对应的pojo为DCategoryProduct,我在DCategory里面额外的加了num字段, 展开
from d_category dc left outer join d_category_product dp on(dc.id=dp.cat_id)
where dc.parent_id = 2
group by dc.id
以上是sql语句,其中d_category对应的pojo为DCategory,d_category_product
对应的pojo为DCategoryProduct,我在DCategory里面额外的加了num字段, 展开
1个回答
展开全部
用本地sql也行
List<Message> list = new ArrayList();
Session session = super.getSession();
有参数放到Map中
//Map<String, Object> map = new HashMap<String, Object>();
String sql = 'select dc.*,count(dp.cat_id) as num
from d_category dc left outer join d_category_product dp on(dc.id=dp.cat_id)
where dc.parent_id = 2
group by dc.id';
Query query = session.createSQLQuery(sql).addEntity(DCategory.class);
//query.setProperties(map);
list = query.list();
List<Message> list = new ArrayList();
Session session = super.getSession();
有参数放到Map中
//Map<String, Object> map = new HashMap<String, Object>();
String sql = 'select dc.*,count(dp.cat_id) as num
from d_category dc left outer join d_category_product dp on(dc.id=dp.cat_id)
where dc.parent_id = 2
group by dc.id';
Query query = session.createSQLQuery(sql).addEntity(DCategory.class);
//query.setProperties(map);
list = query.list();
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询