-->
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.  [ 2 posts ] 
Author Message
 Post subject: Component Mapping with a Discriminator
PostPosted: Mon May 12, 2008 8:33 am 
Newbie

Joined: Fri Apr 11, 2008 6:13 am
Posts: 8
Hi,

I wrote a class as below

Code:
public class Customer
{
    private string name;
    ...
    private Phone homePhone;
    private Phone workPhone;
    private Phone mobilePhone;
    ...
    ///Getters/Setters etc...
}

public class Phone{
    private string code;
    private string number;
    private string extension;
    ...
}


I want to hold all the phones of the customer in Phone table. In Phone table i want to use a discriminator value like (For a customer any type of phones can be inputted)
'H' indicates home phone
'W' indicates work phone
'M' indicates mobile phone

Tables:
Code:
Customer
---------
id
name
...


Code:
Phone
--------
customerID
type
code
number
extension


Is it possible to map Customer class to both Customer and Phone tables? Or do i have to add all fields to Customer table like HOME_PHONE_EXT, HOME_PHONE_NUMBER, ..., WORK_PHONE_CODE,...?

Thanks...


Top
 Profile  
 
 Post subject: Component Mapping with a Discriminator
PostPosted: Tue May 13, 2008 8:29 am 
Senior
Senior

Joined: Thu Jun 21, 2007 8:03 am
Posts: 127
Location: UK
Hi,

It's not clear what you want the discriminator to do here (unless you have subclasses of Phone) - I suspect you need to add an extra property to your Phone class for 'Type' and map that the regular way. Other than that, it's a regular one-to-many mapping of customer to phone.

A further problem you might run into (if your schema is correct above), is that there is no primary key on the Phone table. In that case your mapping might need to declare all the properties of a Phone as a composite-id. If you can, it would be much nicer to have an id column on your Phone table too.

Hope that helps.

Regards,
Richard


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