-->
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: how do I select collection elements via criteria queries?
PostPosted: Thu Nov 30, 2006 8:37 pm 
Newbie

Joined: Tue Jul 13, 2004 9:55 pm
Posts: 7
Location: Tucson, AZ
Hi all, I'm a bit confused as to how I select *only collection elements* (i.e. not their containing parent) via Criteria queries. Given this example from the documentation:

Code:
List results = session.createCriteria(Domestic.class, "cat")
    .createAlias("kittens", "kit")
    .setProjection( Projections.projectionList()
        .add( Projections.property("cat.name"), "catName" )
        .add( Projections.property("kit.name"), "kitName" )
    )
    .addOrder( Order.asc("catName") )
    .addOrder( Order.asc("kitName") )
    .list();


I want to change it so that I just select all of the kittens for some cat. I would think it would look like this:
Code:
List results = session.createCriteria(Domestic.class, "cat")
    .createAlias("kittens", "kit")
    .setProjection( Projections.projectionList()
        .add( Projections.property("kit"))
    )
    .list();


But that doesn't appear to work. In hql I would do something like

Code:
select kittens from Cat as cat join cat.kittens as kittens


But I can't figure out the equivalent Criteria query. Any help would be greatly appreciated.

_________________
Danny Mandel <dmandel at nospam dot tolweb dot org>
Lead Programmer, Tree of Life Project
http://tolweb.org


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.