我正在尝试将本机SQL查询转换为在JPA 2.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对象列表。
谢谢!
最佳答案
JPA不支持UNION,或者使用本机SQL查询,或者执行两个查询。