-->
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: return collection as tuple object
PostPosted: Tue Jul 11, 2006 4:32 pm 
Newbie

Joined: Tue Jul 11, 2006 4:22 pm
Posts: 9
Hello

I have a two objects Doctor and Contact to doctor.
Doctor can have more than one Contact.


i have select like this

select doctor,contactdoctor from Doctor doctor join doctor.contactdoctorSet contactdoctor where doctor.specialization in (:specialization)

if doctor have two contacts it returns two rows like this :
[doctor],[contact1]
[doctor],[contact2]

is any way how it can return collection of contacts as one record
[doctor],[contactSet]

The problem is also with doctor without contact. There r not in final list.

I need it because it is much more faster that get all doctor objects and than ask for collection Hibernate.initialize(doctor.contactdoctorSet )

Can any1 help me ? plz


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 11, 2006 5:39 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
You cannot get a collection back in that way. If doctor.getContactSet isn't good enough for you, the best you can do is Object[] { doctor, contact }.

Your observation that getting the doctor/contact pair is faster than getting the doctor then getting the set of contacts is not correct. When you get the doctor/contact pair, you are also getting the set of contacts in the doctor entity (or at least, you're getting the proxied reference to the set). If your issue is the n+1 selects that would result from the simple "from Doctor" case, use "join fetch":
Code:
select doctor
from Doctor doctor
join fetch doctor.contactdoctorSet c
where doctor.specialization in (:specialization)
This will eagerly fetch all the contacts.

_________________
Code tags are your friend. Know them and use them.


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.