-->
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: one to many select
PostPosted: Mon Mar 07, 2005 12:26 pm 
Newbie

Joined: Mon Feb 28, 2005 6:11 pm
Posts: 6
Hello,

I have one to many foreign key...

something like Person and Phone Numbers...

Code:
Mike
   |- 123584
   |- 234545
John
   |- 498458
   |- 412324
   |- 049783
... etc...

I need to write select that returns all persons with their phone numbers...

There is object Person and PhoneNumber

SELECT person FROM Person person JOIN FETCH PhoneNumber num ORDER BY person.name;

This query returns 5 record with 2 Persons... but I need to return 2 Person objects with his PhoneNumbers (Set) as property of Person.

sorry for my english... ;) I hope, that it is clear...

miso


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 08, 2005 4:39 am 
Newbie

Joined: Mon Feb 28, 2005 6:11 pm
Posts: 6
ok,

I tranformate question:

How Can I get array of unique Persons with phoneNumbers???

Is this OK???
Code:
List list = query.list();
Set distinct = new HashSet( list );
return Arrays.asList( distinct.toArray() );


or there is another way to do this??

thanks, miso


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.