使用JPA CriteriaBuilder将全部和求和 [英] Union All and Sum with JPA CriteriaBuilder
本文介绍了使用JPA CriteriaBuilder将全部和求和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试转换本机SQL查询以在JPA 2.0中使用Criteria API.我在Google上找到了很多Criteria API示例,但要把所有这些部分放在一起确实很难.我希望有经验的人能够帮助我.本机查询如下所示:
I am trying to convert a native SQL query to use the Criteria API in JPA 2.0. I have found a lot of Criteria API examples on Google, but I am having a really hard time putting all of the pieces together. I'm hoping that a more experienced person will be able to help me out. The native query looks like this:
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对象列表.
The original query result set was returning a List of BigDecimal objects.
谢谢!
推荐答案
JPA不支持UNION,或者使用本机SQL查询,或者执行两个查询.
JPA does not support UNION, either use a native SQL query, or execute two queries.
这篇关于使用JPA CriteriaBuilder将全部和求和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文