如何从Hibernate中引用的表中检索数据

时间:2014-01-21 05:17:37

标签: mysql sql hibernate

我正在HibernateMysql合作我有三张桌子

  • Personaldetails
  • Employeedetails
  • Masterrecord

我在这里

  • Employeedetails is referenced from PersonaldetailsMasterrecord is referenced from Employeedetails

  • 请注意 Masterrecord is not directly link from Personaldetails

我附上了

下面的结构格式

enter image description here

我的问题是:

我需要从个人详细信息

访问主记录记录

以下查询无效

select a.fname,a.employeedetails.empId,a.employeedetails.masterrecord.deptCode from pojo.Personaldetails as a

我在Eclipse HQL编辑器中尝试了这个,它的工作原理如下:

enter image description here 我还有其他任何建议......

1 个答案:

答案 0 :(得分:2)

试试这个

SELECT m.* From Masterrecord AS m
         LEFT JOIN  Employeedetails AS e ON e.DeotCode = m.DeotCode 
         LEFT JOIN  Personaldetails AS p ON p.Refld = e.Refld
          GROUP BY p.Refld

这只获取Masterrecord表值。如果需要相同的条件

SELECT m.* From Masterrecord AS m
             LEFT JOIN  Employeedetails AS e ON e.DeotCode = m.DeotCode 
             LEFT JOIN  Personaldetails AS p ON p.Refld = e.Refld WHERE p.Refld = 101
              GROUP BY p.Refld