User has a collection of products:
Code:
session.createQuery("select u, u.products.size from User u");
Results in:
Code:
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_
Hope that helps