I am converting an application that was written in good old JDK 1.3 days to use Hibernate and I need a helping hand on two issues:
1. My object contains a HashMap of various properties. These properties are stored in the separate table with the following structure:
Code:
create table DOC_PROPS (
DOC_ID integer not null,
PROP_NAME varchar(32) not null,
PROP_TYPE char(1) default 'A' not null
constraint CKC_PROP_TYPE check (PROP_TYPE in ('A','I','D','F')),
PROP_VALUE varchar(60) null,
constraint PK_DOC_PROPS primary key (DOC_ID, PROP_NAME)
)
Where PROP_TYPE value defines the type of the property:
A - alphanumeric (String);
Now in my hibernate mapping I am writing:
Code:
<class name="Document" ... >
<property .../>
...
<map name="documentProps" table="DOC_PROPS">
<key column="DOC_ID"/>
<map-key column="PROP_NAME" type="string"/>
<element ??????? - here I stuck />
</map>
</class>
Can someone suggest how to tell hibernate to convert varchar into proper object type based on PROP_TYPE value?
2. The second problem is that legacy Java code for the Document class does not have numeric surrogate key that exists in the database.
Do I have to specify <id> construct in the mapping file? I did put there <composit-id> for the natural key corresponding to the unique DB constraint. All references in the database, however are done via surrogate key.