-->
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 a single table into multiple objects
PostPosted: Thu Feb 18, 2010 2:59 pm 
Newbie

Joined: Fri Oct 16, 2009 12:27 pm
Posts: 7
I need to map a poorly designed table into multiple objects but I am having a difficult time. I can't change the design of the table because it ties into a legacy production system, but I would like to model the objects in a relational fashion once I have the data in hand.

A simplified explanation of the data is as follows:
Name _______ Address Type __ Address
Bob Smith ____ Home _______ 4 Turnout Drive
Bob Smith ____ Work _______ 17 Wheeler Way
John Jones ___ Home _______ 52 Rider Lane
Jen Rogers ___ Work _______ 16 Berry Drive
Jen Rogers ___ Home _______ 4 Industrial Lane

So I would like to map the Name field into a name object(parent) and then have the Address and Address Type fields mapped to an address object(as a child collection).

I tried table per class hierarchy strategy using subclasses but didn't have any luck and I'm not sure that this strategy is the right one to use anyway.

Does anyone have any ideas or could point me to an example that might work for this scenario?


Top
 Profile  
 
 Post subject: Re: Mapping a single table into multiple objects
PostPosted: Fri Feb 19, 2010 11:44 am 
Newbie

Joined: Fri Oct 16, 2009 12:27 pm
Posts: 7
Maybe I can elaborate more to get my question across better:

Given the table I listed:
Name _______ Address Type __ Address
Bob Smith ____ Home _______ 4 Turnout Drive
Bob Smith ____ Work _______ 17 Wheeler Way
John Jones ___ Home _______ 52 Rider Lane
Jen Rogers ___ Work _______ 16 Berry Drive
Jen Rogers ___ Home _______ 4 Industrial Lane

Using Bob Smith I am now getting back 2 people objects as follows:
Bob Smith Home 4 Turnout Drive
Bob Smith Work 17 Wheeler Way

What I would like to see is 1 people object with a collection of 2 address objects.

I've tried component mapping which seems like it could work, but I haven't found any FULL examples using component mapping for dependent collections. Maybe I am missing something in section 7.2 of the nhibernate manual, but I can't seem to put together a working example.


Top
 Profile  
 
 Post subject: Re: Mapping a single table into multiple objects
PostPosted: Mon Feb 22, 2010 7:52 am 
Newbie

Joined: Fri Oct 16, 2009 12:27 pm
Posts: 7
bump


Top
 Profile  
 
 Post subject: Re: Mapping a single table into multiple objects
PostPosted: Mon Feb 22, 2010 8:26 am 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:02 am
Posts: 48
I assume you have another table called person as below:

person name(PK) person job or something
============ ==================

Call this table PersonTable And you have another table for address. call that table AddressTable.

Class Person {

private String personName;

private Set<Address> homeAndWork;
.....
getters/setters

}

here is the mapping
....
<class name="Person" table="PersonTable"...
<id name="id" >
<generator class="assigned"/>
</id>
....
<set name="homeAndWork" table="AddressTable">
<key column="Name" />
<composite-element class="Address">
<property name="addressType" not-null="true"/>
<property name="address" not-null="true" />
</composite-element>
</set>
......


Top
 Profile  
 
 Post subject: Re: Mapping a single table into multiple objects
PostPosted: Mon Feb 22, 2010 3:03 pm 
Newbie

Joined: Fri Oct 16, 2009 12:27 pm
Posts: 7
Unfortunately, I don't have a 'person' table, I only have the single table with all the data. Because of downstream legacy apps I am unable to make any changes to the table, but am hoping that I can map the objects into a reasonable object graph as a facade to the bad database design.

I haven't tried using composite elements as you proposed, I will give it a try (by mapping to same table) and let you know.

Thanks for the help, it is very much appreciated.


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.