Union All and Sum with JPA CriteriaBuilder
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 = ? The original query result set was