Hi,
I would like to define Collection mapping and can not find the right solution.
Source is an object called the Category that owns few Labels, where a Label only belongs to one Category. A Label always has a language (en, de, etc.). And finally per Category the Label is clearly identified by the its language.
Category:
Code:
Map<String, Label> getLabels() Map <String, Label> getLabels ()
returns a Map of all the Labels with the Label language as key of the Map.
Label has "lang", "text" and "description" as fields with corresponding getters and setters.
Every mapping I tried so far did not produce a proper DDL as it should logically look like:
Code:
create table Labels (category integer not null, lang varchar(255), text varchar(255), description varchar(255), primary key (category, lang))
with "category" being the foreign key to Category.
Instead "category, long, text, description" are used as the primary key, which causes to big keys in MySQL and DB2 does not work, because parts of the key can be NULL
Code:
<map name="labels" cascade="all" table="Labels">
<key>
<column name="category"/>
</key>
<map-key type="string" formula="lang"/>
<composite-element class="Label">
<property name="lang" not-null="true"/>
<property name="text" />
<property name="description" not-null="false"/>
</composite-element>
</map>
I also have tried a one-to-many mapping of Label, as described in the section
"6.2.5. One-to-many associations". This does not work because Label is a weak entity, that without the accompanying "strong" entity can not exist. I can not define a primary key for Label.
How should such a mapping look like so that "category, lang" is the primary key?
Thanks in advance.
Thomas