-->
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: getting children from a parent-child relationship
PostPosted: Wed Apr 02, 2008 9:49 am 
Newbie

Joined: Sat Mar 08, 2008 6:52 am
Posts: 4
Hi everybody
my question is as simple to write in SQL as I write below:

select parent.name, child.name, child.item_order
from parent_child parent, parent_child child
where parent.id = child.containerId
order by 3

then, how can i get the same result with HQL of, preferibly, with Criteria API. I tried a lot of things and i have read the chapted dedicated to associations with Criteria in the Hibernate book... and, obviously, i have found answers in this forum without sucess.

the table is so simple:
parent_child (id, parentid, name, item_order),
PK=id, FK= parentid->id (typical recursive relationship)
the order is important (item_order)

any suggestion, plizzzzzzzzzzz

thanx in advance and sorry whether i didnt look for deep enough.

w i l l y

Hibernate version: 3.2.6

Mapping documents: JPA

Name and version of the database you are using:PostgreSQL 8.1


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 03, 2008 2:37 am 
Regular
Regular

Joined: Mon Aug 06, 2007 10:49 am
Posts: 67
Location: Banska Bystrica, Slovakia
try something like this

session.createCriteria(Parent.class)
.createAlias("pathToChild","alias")
.setProjection(Projections.projectionList()
.add(Projections.property("name"))
.add(Projections.property("alias.name"))
.add(Projections.property("alias.order")))
.addOrder(Order.asc("alias.order"))


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.