求助!!! 关于HIBERNATE 左连接问题 5C

1、String sql="SELECT Mgr.Id,U.Name AS applyName,T.Name AS TypeName,U2.Name AS fristapprovername,U3.Name AS secondapprovername FROM TMgrBusiness AS Mgr,TType AS T,TAcUser AS U,TAcUser AS U2,TAcUser AS U3 WHERE Mgr.businesstypeId = T.Id AND Mgr.applyuserId = U.Id AND Mgr.firstapproveruserId = U2.Id AND Mgr.secondapproveruserId = U3.Id ";

可以运行,但查出只有一条记录, 正确应该是170条记录

2、String sql="SELECT Mgr.id,U.Name AS applyname,T.Name AS TypeName,U2.Name AS frist_approvername,U3.Name AS second_approvername FROM TMgrBusiness AS Mgr LEFT JOIN TType AS T WITH Mgr.businesstypeId = T.Id LEFT JOIN TAcUser AS U WITH Mgr.applyuserId = U.Id LEFT JOIN TAcUser AS U2 WITH Mgr.firstapproveruserId = U2.Id LEFT JOIN TAcUser AS U3 WITH Mgr.secondapproveruserId = U3.Id ";

运行出错,出错内容为:严重: Servlet.service() for servlet [default] in context with path [/wlgw] threw exception [java.lang.NullPointerException] with root cause
java.lang.NullPointerException

3、请问一下,为什么加了左连接就不行?HIBERNATE 对左连接是怎样处理的?设谢谢!!!!

不能加LEFT JOIN ON,加了就报错了!

2个回答

朋友,你的左连接语法错了,left join xx on ,你写成with了。

lvranhao
lvranhao Hibernate中不支持关键字on,连接条件是通过映射关联进行的,例如:映射文件中配置<one-to-many>或者使用注解@OneToMany
大约一年之前 回复
qq_34872748
L星火燎原 回复whwwhw1980: 我去,首先,语法是left join on,你别怀疑这个,不然这个Hibernater的作者早就跳河了吗,其次,你应该分析报错的日志java.lang.NullPointerException,这是空指针,你看看数据是不是有问题??
大约一年之前 回复
whwwhw1980
whwwhw1980 加了LEFT JOIN ON就行的,就报错
大约一年之前 回复

你是用的oracle 数据库吗?oracle中表命名别名不能使用as关键字

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问