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 多表查询
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 多表查询