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