I have multiple tables :
- vote
- Question
- Answer
Each of these tables have an authorId field.
I want to output this in an sql query :
MemberId1 . (Nbr of votes + Nbr of Question + Nbr of Answer )
MemberId2 . (Nbr of votes + Nbr of Question + Nbr of Answer )
MemberId3 . (Nbr of votes + Nbr of Question + Nbr of Answer )
How can I do this query with Hibernate criterias ?
In plain SQL I think it would be like this :
select sum(val) from (
select count(*) val from a
union all
select count(*) val from b
union all
select count(*) val from c
union all
select count(*) val from d )
This should do the trick, provided that you have mapped the one-to-many relationships between authors and the three entities in Author :
EDIT :
But since the query is not dynamic, you should probably prefer HQL, which would allow you to write your query even if there’s no mapping of the relationships in Author :