怎么把这个复杂的sql语句改成JPQL?
select a.name, a.surname, b.street, c.location, c.location_desc
from table1 join table2 on b.id = a.some_fk
left join table3 d on d.id = a.id
left join table4 c on c.some2_id = d.some2_fk where a.id = 400;
如果这可以以 JPQL 形式呈现?
怎么把这个复杂的sql语句改成JPQL?
select a.name, a.surname, b.street, c.location, c.location_desc
from table1 join table2 on b.id = a.some_fk
left join table3 d on d.id = a.id
left join table4 c on c.some2_id = d.some2_fk where a.id = 400;
如果这可以以 JPQL 形式呈现?
在不知道实体及其映射的情况下不可能给出明确的答案,但查询看起来像这样:
select a.name, a.surname, b.street, c.location, c.locationDesc
from Entity1 a
join a.entity2 b
left join a.entity3 d
left join d.entity4 c
where a.id = 400;
前提是实体之间存在必要的关联。
JPQL 是面向对象的,它针对 JPA 实体对象而不是数据库表进行操作。您需要更改问题并添加 UML 图表或提供实体类。