我正在尝试将原生SQL查询转换为使用JPA2.0中的Criteria API。我在Google上找到了很多Criteria API的例子,但我真的很难把所有的东西放在一起。我希望一个更有经验的人能帮助我。原生查询如下所示:
select
sum(amount) from firstTable, secondTable
where firstTable.id = secondTable.id
and amount <> 0
and firstTable.id = ?
union all
select
sum(amount) from firstTable, thirdTable
where firstTable.id = thirdTable.id
and amount <> 0
and firstTable.id = ?原始查询结果集返回一个BigDecimal对象列表。
谢谢!
发布于 2012-02-02 22:18:21
JPA不支持UNION,要么使用原生SQL查询,要么执行两个查询。
https://stackoverflow.com/questions/9104989
复制相似问题