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.  [ 4 posts ] 
Author Message
 Post subject: Mapping foreign key relationships with type field.
PostPosted: Sun Feb 06, 2005 7:28 pm 
Newbie

Joined: Sun Feb 06, 2005 6:48 pm
Posts: 2
Location: Vancouver, EH
Hi,

I am new to Hibernate but loving it so far. I have found a couple of cases where I am not able (so far) to get hibernate to map the db to the object model I am trying to use. I have a couple of work arounds figured out, but I am hoping someone can offer a more elegant solution.

An example of the problem is our customer phone data. Currently in our database we have Customer table and a CustomerPhones table. The CustomerPhones table has a foreign key relationship to the customer table and is used to store both home and work phone numbers. The type of phone number (work/home) is identified by a column called phoneType in the CustomerPhones table.

Tables look like
CUSTOMER
customerId
name
addresss
....

CUSTOMER_PHONE
id
customerId
phoneType <== 0=home, 1=work
phoneNumber

I would like to make this transparent to the object model that I am trying to implement so that my new Customer object will have either

1. References to a home and work phone number
ie I can do stuff like
customer.getHomePhone().getNumber();
customer.getWorkPhone().getNumber();

or even better
2. Have the strings automatically loaded into the customer object
customer..getHomeNumber();
customer..getPhoneNumber();

What I would like to do is somewhere in the mapping document I would define the fact that the homePhone number has type 0 and the workPhone has type 1 and hibernate would automatically load the correct property for both the home and work phone.

Hope that makes sense


Daryl


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 06, 2005 8:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You could probably do this, by wrapping an idbag with a where mapping ... I don't have the time to think more about this just now, but I maybe will after sleeping :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 06, 2005 9:40 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Have a look in the test/ dir for Hibernate3. There are some examples like this.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 07, 2005 3:47 am 
Newbie

Joined: Sun Feb 06, 2005 6:48 pm
Posts: 2
Location: Vancouver, EH
I checked out the test dir and not sure, but I think you are talking about using the formula element.

Is this correct and if so us it available in the current stable release ? I am using 2.1.8.

I checked out the dtds and the formula attribute seems to be a lot more prevalent in 3.0.

Hmm, I will have to look at the test dirs a little more tomorrow. Interesting stuff in there though.


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