-->
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.  [ 5 posts ] 
Author Message
 Post subject: Adding restrictions on a JOIN-query
PostPosted: Wed Sep 08, 2010 3:26 pm 
Newbie

Joined: Wed Sep 08, 2010 3:13 pm
Posts: 3
Hi,

Can I retrieve a subset of an entitys child collection with HQL? Or using Criteria?

Code:
@Entity
public class Person

private Set<Child> children


I want the Query to return the Person together with a subset of the children collection.
For example, where children.id = 1;


Top
 Profile  
 
 Post subject: Re: Adding restrictions on a JOIN-query
PostPosted: Wed Sep 08, 2010 3:49 pm 
Newbie

Joined: Mon Aug 02, 2010 11:14 pm
Posts: 10
Oh man! haha, that is similar to a question I've been asking around for a while now. But I will answer your question with a question and try to answer your particular situation, hopefully others will join in and have some better answers.

I am assuming that the children.id is the primary key of children. So why are you trying to retrieve a Person whose child is a unique child. In that case shouldn't you try to retrieve a child? and that child's parent will just be present within the Child bean?

Are you look more for getting a Person whose children have blue eyes or something like that? If that is the case I have used some things called filters. Filters have seem to have some restrictions when it comes to ordering and really puts a huge limitation, never really found a good way. I think hql would be ideal for you in this case. Maybe you can try something like this...

Code:
session.createSql("Select p, c from Person p join p.children pc where pc.eyeColor = 'blue'")


I am assuming something like that, I can test it out and let you know of you can test it out. I currently do not have access to the environment needed to test this. I am not too sure about the join syntax though. Check here for many types of joins... There is this with clause that you can use...
http://docs.jboss.org/hibernate/core/3. ... ryhql.html

Try this too...
Code:
session.createSql("Select p, c from Person p join p.children pc with pc.eyeColor = 'blue'")


Hope this is somewhat relevant to what you needed.

SB


Top
 Profile  
 
 Post subject: Re: Adding restrictions on a JOIN-query
PostPosted: Wed Sep 08, 2010 4:30 pm 
Newbie

Joined: Wed Sep 08, 2010 3:13 pm
Posts: 3
Yes. I want only children having blue eyes. Or children meeting some other condition.
And my where clause doesnt 'take'.


    Top
     Profile  
     
     Post subject: Re: Adding restrictions on a JOIN-query
    PostPosted: Thu Sep 09, 2010 3:07 am 
    Newbie

    Joined: Wed Sep 08, 2010 3:13 pm
    Posts: 3
    Anyone? Can I use the WHERE keyword to as in:

    Code:
    SELECT i FROM Item i JOIN i.products products WHERE products.prize = 10;


    to retrieve the Item and a subset of its products?

    Or should I use the WITH keyword? Or special filtering methods in the Session?


    Top
     Profile  
     
     Post subject: Re: Adding restrictions on a JOIN-query
    PostPosted: Thu Sep 09, 2010 10:52 am 
    Newbie

    Joined: Thu Sep 03, 2009 12:37 pm
    Posts: 13
    hakanmannen wrote:
    Anyone? Can I use the WHERE keyword to as in:

    Code:
    SELECT i FROM Item i JOIN i.products products WHERE products.prize = 10;


    to retrieve the Item and a subset of its products?

    Or should I use the WITH keyword? Or special filtering methods in the Session?


    Why don't you just try before asking?


    Top
     Profile  
     
    Display posts from previous:  Sort by  
    Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.