Etwas später aber in HQL gehts recht einfach (zumindest auf das count(*) bezogen):
Code:
Query query = session.createQuery("select u, u.products.size from User u");
ArrayList<Object> list = (ArrayList<Object>)query.list();
Quote:
Hibernate:
select
user0_.ID as col_0_0_,
(select
count(products1_.user_id)
from
USER_PRODUCTS products1_
where
user0_.ID=products1_.user_id) as col_1_0_,
user0_.ID as ID0_,
user0_.username as username0_,
user0_.password as password0_,
user0_.title as title0_,
user0_.firstname as firstname0_,
user0_.lastname as lastname0_,
user0_.email as email0_,
user0_.account_id as account8_0_
from
USERS user0_
lg
Patrik