-->
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: Best practice for properties list
PostPosted: Fri Mar 25, 2005 9:32 am 
Regular
Regular

Joined: Tue Oct 07, 2003 1:13 pm
Posts: 70
Location: Paris, France
Hi,
I'd like to know what is the best hibernate approach to manage dynamic list of properties ?

Let's take an example :
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>


I think this mapping is not supported, but is there an alternative with hibernate3 ?
I know I could easily create a more classic mapping with one property type in one table, but it'll lead to multiply tables in the database.

Thank you for your feedbak.
Richard


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.