-->
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.  [ 3 posts ] 
Author Message
 Post subject: Inheritance question
PostPosted: Sun Mar 27, 2005 1:00 pm 
Regular
Regular

Joined: Tue Oct 07, 2003 1:13 pm
Posts: 70
Location: Paris, France
Hi,
I'd like to know how can I write the hibernate mapping configuration of the following basic case :

Code:
Class LabelProperty {
String label
int id
... }

Class Country extends LabelProperty ...
Class Color extends LabelProperty ...
and so on


From a personal point of view, I'd like to regroup those lists in one table like this :

Code:
create table label_property
(
  label varchar(100) not null,
  id int not null,
  type int not null,
  primary key (type, id)
)


with these instances of value :

Code:
type, id, label
'CN', 1, 'UK'
'CN', 2, 'France'
...
'CL',1 , 'Red'
'CL',2 ,'Green'
....


It looks like a classic inheritance scheme, except an identifier generation related to the type of LabelProperty. Actually, the dreamed mapping would be :

Code:
   <class name="LabelProperty" abstract="true">
        <discriminator colum="type" type="string"/>
        <property name="label" not-null="true" length="100"/>

        <subclass name="Country" discriminator-value="CN">
      <id name="id" unsaved-value="0">
                    <generator class="native"/>
      </id>
        </subclass>

        <subclass name="Color" discriminator-value="CL">
      <id name="id" unsaved-value="0">
                    <generator class="native"/>
      </id>
        </subclass>

        </class>


This mapping is not supported, is there a way of doing it with hibernate2 ? hibernate3 ?
I know I could easily create a more classic mapping with one property type in one table, but it would lead to multiply tables in the database.
Is there a best hibernate approach to manage dynamic list of properties ?

Thank you for your precious help.

Richard


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 27, 2005 1:30 pm 
Regular
Regular

Joined: Mon Oct 20, 2003 3:14 am
Posts: 53
Location: Sterling, VA, USA
What are you looking for precisely that isn't supported by subclass or a (v3) union-subclass?

_________________
"A statistician is a mathmetician, broken down by age and sex".


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 27, 2005 5:31 pm 
Regular
Regular

Joined: Tue Oct 07, 2003 1:13 pm
Posts: 70
Location: Paris, France
subclasses shares the same identifier generation (based upon the base class), if you look at my previous post, I'd like to have :
- a composite primary key based on the fields : id and discriminator,
- an identifier generation defined for each subclass .....

I hope my problem is more understandable.
Your help is appreciated.
Richard


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