whwwhw1980
whwwhw1980
2018-12-24 14:49

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

5
  • java
  • hibernate

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条回答

为你推荐

换一换