I have a situation where I have a composite key for a table in which one of the columns may be nullable and must be included in the key to insure uniqueness. From what I can tell, this is not supported by Hibernate. This is a legacy database and I am not able to make any changes top the schema.
My mapping looks something like this:
Code:
<hibernate-mapping>
<class name="UserDefField" table="USER_DEF_FIELDS" lazy="false">
<composite-id name="udfId" class="UserDefFieldId" >
<key-property name="programId" type="string" column="PROGRAM_ID"/>
<key-property name="docid" type="string" column="DOC_ID"/>
<key-property name="nullableCol" type="integer" column="NULLABLE_COL"/>
</composite-id>
<property name="dateVal" type="timestamp" column="DATE_VAL"/>
</class>
</hibernate-mapping>
I can tell based on the value of DOC_ID whether or not the nullableCol will be null.
Is there a way that I can map this table to two classes that have different composite keys based on the value of DOC_ID?
Something like class UdfWithNull which is keyed by only programId and docId is used for rows with docId = "ABC" while class UdfWithoutNull is keyed by programId, docId, and nullableCol for rows with docId <> "ABC"?
Any help would be appreciated.[quote][/quote]