-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Criteria and OneToMany property
PostPosted: Fri Jun 10, 2011 8:53 am 
Newbie

Joined: Fri Jun 10, 2011 8:18 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.