假设我有以下表格:
Locations
================
LocationKey, LocationName
Employees
================
EmployeeKey, FirstName, LastName
EmployeeLocationXRef
================
EmployeeLocationXRefKey, LocationKey, EmployeeKey
TimeSheets
=================
TimeSheetKey, EmployeeLocationXRefKey, Minutes
好的,如您所见,为了让我获得所有TimeSheets
for a Location
and Employee
,我可以在 SQL 中执行以下操作
select
*
from TimeSheets ts
join EmployeeLocationXRef ex on (ex.EmployeeLocationXRefKey = ts.EmployeeLocationXRefKey)
join Locations l on (l.LocationKey = ex.LocationKey)
join Employees e on (e.EmployeeKey = ex.EmployeeKey)
where
l.LocationKey = 'xxxx'
and e.EmployeeKey = 'yyyy'
但是我已经尝试了所有我能想到的在 JPA 中使用(带注释)映射的方法@JoinTable
,等等。
任何想法如何做到这一点?不幸的是,这是一个遗留系统,无法更改架构。
编辑
忘了提EmployeeLocationXRef
实体没有直接映射。这可能是真正的问题。我将了解如何创建该实体映射,看看它是否更容易。