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.  [ 3 posts ] 
Author Message
 Post subject: Merge two tables in a single class
PostPosted: Tue Aug 01, 2006 11:59 pm 
Newbie

Joined: Fri Mar 17, 2006 5:23 pm
Posts: 6
Is it possible to merge the columns from two separate tables in a single class?

Example: I have FooClass with attributes Attr1 and Attr2. I'd like to map FooClass.Attr1 to column Col1 in FooTable. No problem there. At the same time, I'd like to map FooClass.Attr2 to column Col2 in BarTable, which is a child of FooTable.

In short:
FooClass.Attr1 <=> FooTable.Col1
FooClass.Attr2 <=> BarTable.Col2

Essentially, this is the opposite of the component element, which maps properties of a child object to columns of the table of a parent class. Instead, I'd like to map columns of a child table to properties of a class. Doable?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 4:30 am 
Senior
Senior

Joined: Wed Jun 15, 2005 4:17 am
Posts: 156
As far as I know you can't do that. But you can map BarTable to BarClass and use delegation in your FooClass to access the properties of BarClass. BarClass can exist as a private field/property of FooClass.

HTH,
Radu


Top
 Profile  
 
 Post subject: Re: Merge two tables in a single class
PostPosted: Thu Aug 03, 2006 3:10 am 
Regular
Regular

Joined: Fri Feb 18, 2005 3:34 am
Posts: 88
Location: Poland/Wrocław
brianberns wrote:
Example: I have FooClass with attributes Attr1 and Attr2. I'd like to map FooClass.Attr1 to column Col1 in FooTable. No problem there. At the same time, I'd like to map FooClass.Attr2 to column Col2 in BarTable, which is a child of FooTable.

In short:
FooClass.Attr1 <=> FooTable.Col1
FooClass.Attr2 <=> BarTable.Col2


You can have a class and subclass so the properties can be mapped to different tables. Also you can have one-to-one relationship.

In fact your scenario is one-to-one because you have an attribute being mapped to the another table somehow. But to have exactly your scenario is not possible in NH in my opinion.

_________________
Please rate this post if you've found it helpfull
Roland


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