Suppose there are 2 tables ...
Table A :
a_id number,
a_val varchar
and Table B :
b_id number,
b_val varchar,
a_id number
Hibernate classes exist for tables A and B.
a_id is the primary key for table A
b_id is the primary key for table B
a_id is a foreign key in table B referencing table A.
We want to get the data from both tables
A and B which in normal SQL is :
select A.a_id,A.a_val,B.b_id,B.b_val from A,B where A.a_id=B.b_id
Question :
What is the best way to read and display the data
when the data does not needs to be persisted?
Method 1 : Create a List of B objects, iterate, and upon
each iteration create a A object. This works fine but is
inefficent if tables A or B are modified to include data
which doesn't have to be displayed.
Method 2 :
Ah ... Is there a Method 2 ?
Something like create a new class, class C, having
composite object members from classes A and B.
Assuming something like that works ... (it doesn't appear that
that can work becase createSQLQuery() must have a table alias
name).
What would be the HSQL to fetch the data?
Any suggestions?
Thanks,
em
|