I have a query like this
SELECT
tableA.field1,
SUM(tableB.field4) AS the_sum
FROM
tableA
LEFT JOIN tableB ON tableA.field1 = tableB.field2
WHERE
/* IN() for multiple possible vals. Use = if only 1 val needed
and then the GROUP BY is unnecessary */
tableA.field1 IN ('val1','val2',val3')
GROUP BY tableA.field1
how to implement the following query in hibernate?. and also i need to return the value as the objects of the curresponding tables. Is it possible?
The query would be almost identical:
That is assuming that there is an association from EntityA to EntityB using a.field1 as a foreign key to b.field2 (or vice-versa). If you don’t have such an association, it’s impossible. left joins are only possible with associations.