iteye_9203 2011-05-24 21:24
浏览 790
已采纳

Hibernate 中多张表连接,要求左连接,HQL语句怎么整。

有5张表:
A表:id,bid
B表:id,cid
C表:id
D表:id,cid
E表:id,did

B、D是C的子表,A是B的子表,E是D的子表。
全部左连接,要求顺序:A-B-C-D-E 可以反着:E-D-C-B-A,没什么区别,但是不能乱只能这两种。

HQL语句怎么写?我自己写的第一条:
from A a left join B b on a.bid = b.id
left join C c on b.cid = c.id
left join D d on d.cid = c.id
left join E e on e.did = d.id

这条语句提示on关键字有错。

第二条:
from A a left join B b
left join C c
left join D d
left join E e
where a.bid = b.id and b.cid = c.id and d.cid = c.id and e.did = d.id

错误:
org.springframework.orm.hibernate3.HibernateQueryException: Path expected for join! [ from com.newer.business.pojo.MProcedureModule mpme left join MProcedure mpe left join MManufacture mme left join MProceduring mpg left join MProcedureModuling mpmg where mpme.MProcedure.id = mpe.id and mpe.MManufacture.id = mme.id and mpg.MManufacture.id = mme.id and mpmg.MProceduring.id = mpg.id and mme.id = 1]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: Path expected for join! [ from com.newer.business.pojo.MProcedureModule mpme left join MProcedure mpe left join MManufacture mme left join MProceduring mpg left join MProcedureModuling mpmg where mpme.MProcedure.id = mpe.id and mpe.MManufacture.id = mme.id and mpg.MManufacture.id = mme.id and mpmg.MProceduring.id = mpg.id and mme.id = 1]
Caused by:
org.hibernate.hql.ast.QuerySyntaxException: Path expected for join! [ from com.newer.business.pojo.MProcedureModule mpme left join MProcedure mpe left join MManufacture mme left join MProceduring mpg left join MProcedureModuling mpmg where mpme.MProcedure.id = mpe.id and mpe.MManufacture.id = mme.id and mpg.MManufacture.id = mme.id and mpmg.MProceduring.id = mpg.id and mme.id = 1]

没办法了,自己想不出,只能来请各位看看指点指点我。谢谢!!!

  • 写回答

7条回答 默认 最新

  • the big fundmental 2011-05-27 18:42
    关注

    hibernate的左连接必须在配置文件中指定,如果想方便点些,可以直接用SQL本土语句。
    HQL例子,这在配置文件中都指定了
    from Cat as cat
    inner join cat.mate as mate
    left outer join cat.kittens as kitten
    SQL方便点,session.CreateSQLQuery(sql)
    我就直接用的SQL,而且连接这样写A.id (+)= B.id简单一点

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(6条)

报告相同问题?

悬赏问题

  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程