如何将嵌套SQL转换为HQL [英] How to convert nested SQL to HQL

查看:93
本文介绍了如何将嵌套SQL转换为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' ); 

如果您检查规范。您可以找到关于子查询 there。


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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆