【问题标题】:Right join JPA query fails to get exact ouput右连接 JPA 查询无法获得准确的输出
【发布时间】:2018-02-06 11:18:45
【问题描述】:

我在 JPA 中遇到了这个查询的问题

员工表

id,....,location_id (id 1,2,3,4 assigned to location id 1)

EmployeeMaster 表

id,.....,date, employee_id(employee_id 1 and 2 having records in this table)

JPA 查询

select me,ms from EmployeeMaster ms right join ms.employee me where ms.date between ?2 and ?3 and me.location.id = ?4

输出

employeeMaster,employee1
employeeMaster,employee2

因为日期之间只有两个员工在 EmployeeMaster 表中有记录

我希望输出是这样的

employeeMaster,employee1
employeeMaster,employee2
null,employee3
null,employee4

请帮我解决这个问题

谢谢。

【问题讨论】:

    标签: java mysql hibernate jpa


    【解决方案1】:

    而不是检索employeeMaster 检索员工,你会得到你的结果。

    【讨论】:

    • 仍然得到相同的结果。
    • 您是如何实施我的建议的?
    • 从 EmployeeMaster 中选择我 ms 右加入 ms.employee 我 where ms.date 介于 ?2 和 ?3 之间且 me.location.id = ?4
    • @AshokReddy 在您使用右连接时应使用,请改用左连接
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-15
    • 2013-01-07
    • 1970-01-01
    相关资源
    最近更新 更多