我正在尝试将 native SQL 查询转换为使用 JPA 2.0 中的 Criteria API。我在 Google 上找到了很多 Criteria API 示例,但我很难将所有部分组合在一起。我希望有更有经验的人能够帮助我。 native 查询如下所示:
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 查询,要么执行两个查询。
关于jpa - 使用 JPA CriteriaBuilder 进行 Union All 和 Sum,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9104989/