-->
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.  [ 2 posts ] 
Author Message
 Post subject: HQL: left join fetch with filter?
PostPosted: Tue Jun 21, 2011 6:09 am 
Newbie

Joined: Tue Jun 21, 2011 5:33 am
Posts: 7
I recently started using hibernate to manage the queries in my webapplication, and encountered a problem for that I've found some forum posts but no satisfying answer.

I often have to fetch joined information from various tables, wherefore I'd like to use a Query element:

Code:
Query query = this.getSession().createQuery
      ("select distinct fipo from Fipo fipo " +
            "left join fetch fipo.gvfis gebs " +
                                "where fipo.namen1 like :name)


Now I want to filter the set fipo.gvfis as I only want to fetch certain entries.
A native SQL Query would look like this:

Code:
select * from FIPO f left outer join GVFI g on
g.FIPOID = f.FIPOID and g.GVEART = 'GEB' where f.NAMEN1 like ":name";


But as I searched for information on the issues it seems to be impossible to specify this kind of query in HQL.
The suggested workaround is to use filters, but I have no clue how this can be implemented?

Thanks for any hints,
Daniel


Top
 Profile  
 
 Post subject: Re: HQL: left join fetch with filter?
PostPosted: Fri Jun 24, 2011 9:32 am 
Newbie

Joined: Tue Jun 21, 2011 5:33 am
Posts: 7
So far I think I can do what I described using the "with"-Keyword, see above.
But now that I applied the filter, how can I read the filtered associations?
When I use the getter() method of the main entity - Fipo.getGvfis() - in the query I will always generate a new query without the filter.

Code:
Query query = this.getSession().createQuery
      ("select distinct fipo from Fipo fipo " +
            "left join fetch fipo.gvfis as gebs with gebs.gveart = 'GEB' " +
                                "where fipo.namen1 like :name)


Or is it a better idea to use Criteria or native queries?
Thanks, Daniel


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

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.