如何将嵌套SQL转换为HQL [英] How to convert nested SQL to HQL
问题描述
我是Hibernate和HQL的新手。我想在HQL中编写一个更新查询,其SQL等效如下:
更新病人集合
`last_name `=new_last,
`first_name` =new_first
其中id =(从doctor $ b $中选择doctor_id,其中clinic_id = 22且city ='abc_city');
doctor_id
是PK < c>医生,在患者
中是FK和PK。有一对一的映射。
相应的Java类是Patient(带有lastName,firstName,doctorId)和Doctor(带有doctorId)。
任何人都可以告诉上述SQL查询的HQL等价物吗?
非常感谢。
String update =update Patient p set p.last_name =:new_last,p.first_name =:new_first where p.id = some(doctor.clinic_id = 22,city ='abc_city' );
I am new to the Hibernate and HQL. I want to write an update query in HQL, whose SQL equivalent is as follows:
update patient set
`last_name` = "new_last",
`first_name` = "new_first"
where id = (select doctor_id from doctor
where clinic_id = 22 and city = 'abc_city');
doctor_id
is PK for doctor
and is FK and PK in patient
. There is one-to-one mapping.
The corresponding Java classes are Patient (with fields lastName, firstName, doctorId) and Doctor (with fields doctorId).
Can anyone please tell what will be the HQL equivalent of the above SQL query?
Thanks a lot.
String update = "update Patient p set p.last_name = :new_last, p.first_name = :new_first where p.id = some (select doctor.id from Doctor doctor where doctor.clinic_id = 22 and city = 'abc_city')";
You can work out how to phrase hql queries if you check the specification. You can find a section about subqueries there.
这篇关于如何将嵌套SQL转换为HQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!