我是Hibernate和HQL的新手。我想在HQL中编写一个更新查询,其SQL等效项如下:
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是的PK doctor,是的FK和PK patient。有一对一的映射。
doctor_id
doctor
patient
相应的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 (select doctor.id from Doctor doctor where doctor.clinic_id = 22 and city = 'abc_city')";
如果您检查规范,则可以算出如何用语表达hql查询。您可以在此处找到有关子查询的部分。