-->
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: Retrieve one parent and one child only in one HQL ?
PostPosted: Thu Dec 30, 2004 6:40 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
Hi friends

I want to know if it is possible retrieve one parent and only one child in on HQL.
I mean that I want to get a child and a parent in one sql .

I try this:

Code:

select p.parentName,c.childName,elements(p.childSet).get(0) from Parent p,Child c



But it can't parse compile. Hibernate's HQL is object SQL, So I think it maybe work in this way,right?

If someone know how to do it ,please tell me , Thks!

_________________
You are not alone...


Top
 Profile  
 
 Post subject: :(
PostPosted: Thu Dec 30, 2004 11:30 pm 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
It is Possible? Or anyone has another solution?

_________________
You are not alone...


Top
 Profile  
 
 Post subject: Retrieve one parent and one child only in one HQL
PostPosted: Fri Dec 31, 2004 1:07 am 
Newbie

Joined: Mon Dec 13, 2004 2:32 am
Posts: 8
Sound like a one-2-oen relationship why not try one-2-one relationship feature of hibernate.

Check out the hibernate manulate for feature capabilities.


Top
 Profile  
 
 Post subject: Re: Retrieve one parent and one child only in one HQL ?
PostPosted: Fri Dec 31, 2004 9:39 am 
Contributor
Contributor

Joined: Thu Nov 06, 2003 9:49 pm
Posts: 104
Location: New York, NY
Yashnoo wrote:
Hi friends

I want to know if it is possible retrieve one parent and only one child in on HQL.
I mean that I want to get a child and a parent in one sql .

I try this:

Code:

select p.parentName,c.childName,elements(p.childSet).get(0) from Parent p,Child c



But it can't parse compile. Hibernate's HQL is object SQL, So I think it maybe work in this way,right?

If someone know how to do it ,please tell me , Thks!


That seems like the hard way to do it. If you have a backpointer from Child to Parent e.g. a many-to-one from child to parent, and that is mapped to the 'parent' property of child, you can do this:
Code:
select c.childName, c.parent.parentName from Child c


or even:
Code:
from Child c


and then use Java code in your application to access the properties, e.g.
Code:
Child c = ... get result from the above query ...
String x = c.getParent().getParentName();
String y = c.getChildName();


Top
 Profile  
 
 Post subject: :)
PostPosted: Sun Jan 02, 2005 6:30 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
Thank you . I WILL try it !

_________________
You are not alone...


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.