如何在hql@query中集成两个表列

i86rm4rw  于 2021-06-27  发布在  Java
关注(0)|答案(1)|浏览(387)

我们不能使用union,因为hql不支持它。在hql中不使用union和join组合两个不同表的替代方法是什么?
我们不能用“或”来组合表,因为没有类似的表或列。
我们也可以做两个不同的查询,然后在一个列表中合并,但这对我们不好,所以如果有任何解决方案,请建议
我们希望在hql中实现的sql查询。

select m.* from (select a.* from a1 a where a.id=1 union select b.* from b1 b where b.id =1) m order by m.id desc
k7fdbhmy

k7fdbhmy1#

这些表有相同的数据结构吗?如果是,您可以使用insert into…select语句,因为hql支持它。
在sql中,它看起来像:

insert into a select b.* from b where b.id =1

对于hql中的insert into…select语句,请查看以下内容:
https://mkyong.com/hibernate/hibernate-query-examples-hql/

相关问题