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.
|