hibernate 多表查询,返回新定义的对象

SessionFactory sessionFactory=Configuration.buildSessionFactory("hibernate.cfg.xml");
Session session=sessionFactory.currentSession();

[color=red]String hql="select new A(a.ab001,a.ab002,a.ab006,b.aa002 as ab003) from db_xtwh_bmb as a left outer join db_xtwh_ryb as b on a.ab003=b.aa001 where a.ab004= "0 ""; [/color]

Query query=session.createQuery(hql);
List <A > list=query.list();
return list;


hibernate 左外连接的写法:
select mother, offspr, mate.name from DomesticCat as mother inner join mother.mate as mate left outer join mother.kittens as offspr 这是正确的左连接 语句 ,但这个是在表之间配置了关系后才能使用的我想问的就是,在没配置表与表之间的关系的情况下,怎么使用HQL语句 左连接 查询?

跟sql的左外连接不一样

在hibernate中使用左外链接要先建立关联
否则只能通过一些小技巧来完成

参考:[url]http://mayabin.iteye.com/blog/123886[/url]


这里还有另外一种左外链接的写法:
select cu.customerid,cu.enpname,cu.phone,cu.mobile,cu.EMail,sd.dname
from Customerinfomation as cu, Sysdata as sd Where sd.did(+)=cu.validflag

用(+)代替left join

[url]http://77857.blog.51cto.com/67857/153519[/url]

hibernate 多表查询
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值