Hello,
We are using Hibernate 3.3.1.GA, old I know but no choice... I also searched a lot on Google/this forum about that but haven't fund a solution yet..
I'm trying to write the following HQL query with Criteria API :
Code:
select distinct a.bs from A as a
where bs is :
Code:
@OneToMany(fetch = FetchType.LAZY)
private Set<B> bs;
This is how I'm trying to do it :
Code:
Criteria criteria = session.createCriteria(A.class);
criteria.setProjection(Projections.groupProperty("bs"));
The HQL is generating a SQL looking like :
Code:
select
distinct b1_.id as id8_,
b1.last_changed as last3_8_
from
public.a a0_
inner join
public.b b1_
on a0_.id=b1_.a_id
The Criteria doesn't work, producing :
Code:
select
this_.id as y0_
from
public.a this_
group by
this_.id
What I tried :
1/
Code:
criteria.createAlias("bs", "bs_", Criteria.LEFT_JOIN);
bs_ is not recognized if I used it as property name, I must use something like bs_.id. It then works, but have to use a ResultTransformer to get my real objects. Really inefficient...
2/
Code:
criteria.createAlias("bs", "bs_", Criteria.LEFT_JOIN);
criteria.setFetchMode("bs", FetchMode.JOIN);
A bit better, but not that yet...
Code:
select
this_.id as y0_
from
public.a this_
left outer join
public.b b1_
on this_.id=b1_.a_id
group by
this_.id
So, after looking into CriteriaLoader, it looks like that bs is a Set type and the sql generation fails.
I'll use a ResultTransformer with a cache for the moment, but if you have any idea, there are welcome!
Thanks