-->
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: Problems mapping denormalized tables
PostPosted: Mon Jan 30, 2006 11:25 pm 
Newbie

Joined: Mon Jan 30, 2006 10:53 pm
Posts: 7
I'm trying get NHibernate to work with tables that are not normalized properly (and I can't do anything about it)

Here is a sample table:

CONTACT1
NAME, ... ADDRESS1, ADDRESS2, ADDRESS3, CITY, STATE, ZIP, ... PHONE1, PHONE2, PHONE3

I'm having trouble dealing with the multiple ADDRESS fields and the multiple PHONE fields, for different reasons.

The Address fields I want to role up into a class that contains:

Address
---------
Street
City
State
Zip

So I basically want to concatenate the 3 Address fields with a line break between them and put it in the "Street". Another comparable solution would be to use collection of "Streets" for each Address.

The second problem are the phone numbers.

I want them each in there own class of:

PhoneNumber
Number


I know I could solve these using a view on the backend, but I'm trying to get this done within NHibernate. If it makes a difference, this application only reads the data, it does not write it back.

I'm very new to Hibernate and I'm trying to wrap my head around all of this. I've read the documentation on hibernate.org... if anyone can point me in the right direction I'd be very appreciative.

Thanks,
Patrick


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 30, 2006 11:56 pm 
Newbie

Joined: Fri Jan 27, 2006 9:03 pm
Posts: 3
You should look at using components in the nhibernate/hibernate 2.1 documentation.

Basically, a component allows you to use a finer grained class model than a one-one mapping between tables and classes. You can make a contact contain one address object (with the fields you mention) and three phone classes using components.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 1:18 am 
Newbie

Joined: Mon Jan 30, 2006 10:53 pm
Posts: 7
Thanks for the reply. I read over the component documentation and I still cannot see how that helps me in this situation. Can someone please explain a litte more?

Thanks,
Patrick


Top
 Profile  
 
 Post subject: Component and UserType
PostPosted: Tue Jan 31, 2006 3:09 am 
Regular
Regular

Joined: Tue Jan 03, 2006 7:21 am
Posts: 85
I believe you need to write your own custom type to map the 3 address fields to a street property and also use Component as already stated in a previous post.

Your mapping could be something like this:

<component name='Address1' class='eg.Address'>
<property name='Street' type='eg.CustomAddressType'>
<column name='Address1 />
<column name='Address2 />
<column name='Address3 />
</property>
<property name='City' />
<property name='State' />
<property name='Zip' />
</component>

Please read the doc for more info.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 1:17 pm 
Newbie

Joined: Mon Jan 30, 2006 10:53 pm
Posts: 7
Thanks samujab!

I modified the DoubleStringType example slightly to TripleStringType to allow the "Street" to work the way I want. Ideally I'd like to have this type dynamically size itself based on the number of columns, but its working for now.


However I still don't have a clue how to get the three PHONE fields each into their own class. Anybody else?

Thanks!
Patrick


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.