JPA 2.0でCriteria APIを使用するためにネイティブSQLクエリを変換しようとしています。私は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オブジェクトのListを返していました。
ありがとうございました!
なぜUNIONがサポートされていないのですか? – santedicola
EclipseLinkはUNIONをサポートしていますhttp://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/JPQL#UNION – James