-->
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: Criteria: query a class and return list based on a property
PostPosted: Thu Oct 09, 2008 5:34 am 
Newbie

Joined: Wed Oct 08, 2008 10:11 am
Posts: 3
I'm having difficulties constructing a criteria typed query.

Let's say we have a Hierarchy class with 2 properties called Parent and Child of a certain class, Foo for instance. The Foo class has no knowledge of Hierarchy.

I want to query the Hierarchy class to find all childs with a certain parent.

Code:
ICriteria criteria = session.CreateCriteria(typeof(Hierarchy));
criteria.Add(Expression.Eq("Parent", parent));


This would return all the Hierarchy objects with the parent, but I want a list of Foo. (without looping through the Hierarchy objects and filtering the childs out)

But for the love of God, I can't figure out how, I've been fooling around with Projections and ResultTransformers, without success.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 09, 2008 11:24 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
If you don't want to traverse the graph of objects Jav-style, use HQL instead, specifying parent and child in the select list.

When more than one thing is put in the select list of an HQL query, Hibernate returns the results as an array of Object[].
Simply traverse that array, not minding the repeated parent.

_________________
Gonzalo Díaz


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.