-->
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.  [ 3 posts ] 
Author Message
 Post subject: Multiple objects to single row mapping
PostPosted: Sun Oct 12, 2003 12:13 pm 
Newbie

Joined: Thu Oct 09, 2003 11:32 am
Posts: 2
Can Gavin, or any one of you, kind ladies and gentleman explain once and for all how to deal with this (SEE TOPIC NAME).
Most of us work in the environment where SQL queries are complex and database schema already exists. So we have to work backwards, creating domain model from existing schema. This is awkward but such is life.
Many times we have to fetch results from many tables, and, therefore, brind many domain objects back. If several rows come back on Query.list() execution, what types of objects are coming back?

According to Hibernate Reference doc, "Hibernate queries sometimes return tuples of objects, in which each tuple is returned as an array:

Iterator foosAndBars = sess.iterate(
"select foo, bar from Foo foo, Bar bar " +
"where bar.date = foo.date");

while ( foosAndBars.hasNext() ) {
Object[] tuple = (Object[]) foosAndBars.next();
Foo foo = tuple[0]; Bar bar = tuple[1];
....
} "

What if there are many more than 2?
select patient, exam, examCode
from Patient as patient, Exam as exam
join exam.patientOrder as patientOrder,
ExamCode as examCode, Organization as org
where examCode.examCodeId=exam.examCodeId
and patientOrder.patientId=patient.patientId
and org.organizationId=:organizationId
and patientOrder.orderDate between :startDate and :endDate
and exam.dvStatus ='NO IMAGES'
order by patientOrder.orderDate

in this case, where each PATIENT, EXAM, and EXAM_CODE are mapped indivudually to their corresponding domain objects, what will be returned in the list?
Please advise, as this is a major point for me. Thank you very much.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 12, 2003 2:43 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You get an Object[] with more than two fields if more than two objects are selected. In your case, you get a Patient, an Exam and an ExamCode.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject: Multiple objects to single row mapping
PostPosted: Sun Oct 12, 2003 5:21 pm 
Newbie

Joined: Thu Oct 09, 2003 11:32 am
Posts: 2
Thank you Christian. I will try that tomorrow.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.