-->
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: cross table joins
PostPosted: Wed Nov 30, 2005 8:15 pm 
Newbie

Joined: Wed Nov 02, 2005 12:08 am
Posts: 7
Location: Sydney,Australia
I am looking at implementing cross table joins in Hibernate and am unsure of the approach. I am looking at including the queries in the XML table definition file. I have a table A and table B and I want to access all fields from both tables from my Java class.

As I see it there are two possibilities to accomplish this:
1) create a simple select query in the XML definition of tableA eg select * from tableA, and also in the XML definition for tableB - select * from tableB. I could then have a ClassA and ClassB representing these tables. We would then join the results of the two queries via Java.

2) include a cross table query eg select * from tableA, tableB, to the XML definition of one of the tables with a ClassAB representing the combination of all the fields from both tables.

I would prefer the second option but am unable to fing enough info on how to do it.
Does anybody have any ideas and if so some code examples?

Appreciate any help on either option.

thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 9:44 pm 
Beginner
Beginner

Joined: Tue Jun 07, 2005 11:36 pm
Posts: 22
If the columns of each table have no distinct meaning unto themselves, then you want to use the join element:

http://www.hibernate.org/hib_docs/v3/re ... ation-join

If the tables do have meaning by themselves, then you want to setup some simple one-to-one mappings between 3 classes - ClassA and ClassB each represent table A and B, and ClassC has a one-to-one relationship with ClassA and a one-to-one with ClassB. (Like a Person has a Address and has a Car):

http://www.hibernate.org/hib_docs/v3/re ... n-onetoone

_________________
Useful? Hit me with a point! Completely off base? Ya, well, what do you expect from a newbie...


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.