Complex sql query and JPQL

强颜欢笑 提交于 2019-12-24 00:59:07

问题


How to change this complex sql statement into 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;

If this is possible to present in the JPQL form?


回答1:


Impossible to give a definitive answer without knowing the entities and their mapping, but the query would look like this:

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;

provided the necessary associations between entities are there.




回答2:


JPQL is object oriented, it operates against JPA entity objects ,not database tables. Either you need to change the Question and add an UML diagramm or provide the Entity classes.



来源:https://stackoverflow.com/questions/13572493/complex-sql-query-and-jpql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!