-->
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: ont-to-many: how to query one?
PostPosted: Sun May 30, 2004 9:52 pm 
Newbie

Joined: Mon Apr 05, 2004 3:48 am
Posts: 8
Now there are two classes, for example Parent and Child, as we all know one parent maybe has many children.
Parent
-id (attribute)
-name (attribute)
Child
-id (attribute)
-name (attribute)
-parentID (attribute)
-age (attribute)

If I know the information about name and parentID of a child, how to query the age information about this child?

1. acording to relation of Parent and Child, firstly load Parent with parentID, secondly get all children of this parent, finally use child's name to get the child instance.

2. Hibernate provides a "createSQLQuery" funcation in Query class, but the sql format in the function is not same as the sql used in database client.

any idea else?
thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 31, 2004 5:04 am 
Senior
Senior

Joined: Sun Mar 14, 2004 10:16 am
Posts: 129
Location: Ankara
Quote:
1. acording to relation of Parent and Child, firstly load Parent with parentID, secondly get all children of this parent, finally use child's name to get the child instance.


Why you need to query the Parent to get a child attribute?
just query the Child -))

"Select child.age from Child child where child.parentID =....

_________________
-developer


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.