Hi,
I wonder if the following is possible within hibernate. Within my Object model I have a class 'EntityDescription' which stores the title and a descriptive text for a specified language for a corresponding entity. The title resp. the description are stored within a HashMap each, with the language as key.
For the relational model it seems quite convenient to me, that the sets of 'EntityDescription' are mapped to one table:
create table DESCRIPTIONS (
ENTITY_ID bigint not null,
DESCRIPTION varchar(255),
ISO_LANG_CODE varchar(2) not null,
TITLE varchar(255),
primary key (ENTITY_ID, ISO_LANG_CODE)
);
The standard SQL-operation for a new title or description is an INSERT-statement which leads to a 'Duplicate key or integrity constraint violation message'. The statement should be an update, if there exists already a row with the composite keys.
Is it possible to tell hibernate, that there are multiple sets mapped to one table? Or to I have to cope with redundancy and let hibernate manage the sets by one table for each set with exact the same key-values?
Hibernate version: 2.1.7c
Mapping documents:
Code:
<component
name="entityDescription"
class="com.raytion.catalog.model.EntityDescription"
>
<map
name="descriptions"
table="DESCRIPTIONS"
lazy="false"
sort="unsorted"
inverse="false"
cascade="all"
>
<key column="ENTITY_ID"/>
<index
column="ISO_LANG_CODE"
type="string"
length="2"
/>
<element
column="DESCRIPTION"
type="string"
not-null="false"
unique="false"
/>
</map>
<map
name="titles"
table="DESCRIPTIONS"
lazy="false"
sort="unsorted"
inverse="false"
cascade="all"
>
<key column="ENTITY_ID"/>
<index
column="ISO_LANG_CODE"
type="string"
length="2"
/>
<element
column="TITLE"
type="string"
not-null="false"
unique="false"
/>
</map>
</component>