-->
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: How to do a SQL join Hibernate style
PostPosted: Mon Aug 02, 2004 9:03 pm 
Beginner
Beginner

Joined: Fri Mar 12, 2004 8:40 pm
Posts: 30
Location: SF Bay Area
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 9:05 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Would reading the documentation help with some of those questions?

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


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.