-->
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.  [ 5 posts ] 
Author Message
 Post subject: Mapping Multiple Tables to One Class
PostPosted: Thu Jun 15, 2006 4:16 pm 
Newbie

Joined: Thu Jun 15, 2006 4:03 pm
Posts: 3
Thanks in advance for your help. I am attempting to map data from multiple tables into a single class. Here is the table setup:

Table Foo
column a (pk)
column b

Table Bar
column a (pk)
column c (pk)
column d
column e

There is a one-to-many relationship between Foo and Bar. I have a class that stores values for a, b, and d. I would therefore like to perform the following query:

select a, b, d from Foo, Bar where a=? and e=?

Assume that e is unique. Can I set up a mapping and a corresponding query to do this? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 9:19 pm 
Regular
Regular

Joined: Wed Jan 07, 2004 5:16 pm
Posts: 65
Location: CA, USA
AFAIK you can not map multiple tables to one class, unless you are mapping an inheritance hierarchy, which from what you are describing you are not.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 15, 2006 9:49 pm 
Newbie

Joined: Sun May 28, 2006 11:24 am
Posts: 13
[quote="khooke"]AFAIK you can not map multiple tables to one class, unless you are mapping an inheritance hierarchy, which from what you are describing you are not.[/quote]

How about joining the tables and mapping the result to a Bean? Looks like the tables have been normalized and you want a denormalized view. Hmm there for you could also make a DB view (which just looks like a table) and map that to a bean.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 16, 2006 7:40 am 
Beginner
Beginner

Joined: Fri May 26, 2006 7:15 am
Posts: 20
Location: Vandavasi, TamilNadu
Is this u needed?

select new FooBar(f.a,f.b,b.d)
from Foo as f inner join Bar as b on f.a=b.a
where f.a=? and b.e=?

Appropriate constructor - FooBar.java - FooBar(*,*,*)

Refr domnt[select new..]
------------------------------------------------------------------------

_________________
gajini
------------------


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 16, 2006 8:42 am 
Newbie

Joined: Thu Jun 15, 2006 4:03 pm
Posts: 3
The SQL in the last post is indeed the kind of thing I'm looking for, but my question is how to configure a mapping for such a bean. The view idea is a good one, although I'm not sure if I have any control over the datasources. I was trying to isolate my solution to the .xml mapping. I looked at the <join> tag, but I'm under the impression that it accomodates only one-to-one relationships. Am I mistaken in this? Or is there a better way to map the join of tables in a one-to-many relationship? Am I making any sense at all? Is the weekend here yet?


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