我想轉換原生SQL查詢以使用JPA 2.0中的Criteria API。我在Google上發現了很多Criteria API示例,但我很難將所有這些部分放在一起。我希望一個更有經驗的人能夠幫助我。原生查詢如下所示:聯盟所有和與JPA CriteriaBuilder結合
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對象列表。
謝謝!
你知道爲什麼不支持UNION嗎? – santedicola 2012-10-26 10:09:22
EclipseLink支持UNION http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/JPQL#UNION – James 2012-10-31 14:09:32