-->
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.  [ 1 post ] 
Author Message
 Post subject: Inheritance mapping question.
PostPosted: Wed Apr 15, 2009 11:49 pm 
Newbie

Joined: Tue Nov 18, 2008 5:47 am
Posts: 5
Hi there,

The DB I'm working on has a generic table called REF_CODES to store all types of codes and their descriptions. eg, address type, contact type ect.

Code:
schema of REF_CODES:
domain, code, description (domain and code are pk columns)

example data
add_type, P, postal
add_type, R, residential
contact_type,G, general
contact_type,O, other

what I wanted to do is do inheritance mapping as follow:

Code:
@Entity
@Table(name = "ref_codes")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "domain")
public abstract class RefCodes {
@EmbeddedId
private RefCodesId id;

@Embeddable
private class RefCodesId implements Serializable {

@Column(name = "domain")
private String domain;
@Column(name = "code")
private String code;

}
}

@Entity
@DiscriminatorValue(value = "add_type")
public class AddressType extends RefCodes implements Serializable {

@Column(name = "code")
private String code;

@Column(name = "description")
private String description;
}


And then the AddressType can be used by Address class in ManyToOne mapping as follow;

Code:
@Entity
@Table(name = "addresses")
public class Address implements Serializable {

private String name;

@ManyToOne
@Joincolumn(name = "add_type_code")
private AddressType type;

}


The problem I'm having is that in Address class the ManyToOne mapping to AddressType needs to join 2 columns as AddressType(RefCode) has a composite PK, but the Address table only stores address code, how do I let the join query know the value of the domain as 'add_type' then.
Or, is there a way to override the id of AddressType class as 'code'?

Is this mapping doable? Thanks.
Code:


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.