SQL到Hibernate查询语言(HQL) - 缺少IN

时间:2013-12-04 21:03:09

标签: java sql hql

要转换的SQL语句

select * from tableA where columnA is not null 
order by cast(columnA as int), columnB
union all
select * from app_data_program where columnA is null order by columnB

我的HQL尝试:

From TableA a where a.columnA is not null 
order by cast(a.columnA as int), a.columnB 
union all TableA b where b.columnA is not null order by b.columnB

当我将HQL转换为SQL以进行测试时,我得到以下结果:

SQL Error: Missing IN or OUT parameter at index:: 1

1 个答案:

答案 0 :(得分:0)

HQL不允许使用UNION ALL sql构造。

您必须执行两个不同的查询,然后才能合并它们的结果。

所以你会:

首先查询:

From TableA a where a.columnA is not null 
order by cast(a.columnA as int), a.columnB

第二次查询:

TableA b where b.columnA is not null order by b.columnB