hi,
i'm using Hibernate 3.1 (with Oracle 9i) and I have a question about mapping Maps.
I have an object called "SgBackendMapping" which has a Map field named "defaultAttributes". The keys and values are to be taken form the table "SG_DEFAULT_ATTRIBUTE". Entries of "SG_DEFAULT_ATTRIBUTE" reference "SgBackendMapping's" by a composite foreign key ( "BACKEND_ID" and "ORGANIZATION_ID" ) My problem is that I cannot specify a composite foreign key (as 'key') in the Map mapping.
I show in the following mapping file what I would like to do, but it is unfortunately not possible...
The Hibernate Reference Documentation 3.1 rc1 suggests that it was possible, but does not mention, how:
"Collection instances are distinguished in the database by the foreign key of the entity that owns the collection.
This foreign key is referred to as the collection key column (OR COLUMNS) of the collection table. The collection
key column is mapped by the <key> element."
any ideas? thank you!
Balazs
Code:
<hibernate-mapping package="com.baca.save.common.model.metadata">
<class name="SgBackendMapping" lazy="false" table="SG_BACKEND_MAPPING">
<composite-id>
<key-many-to-one name="backend" class="SgBackend" >
<column name="BACKEND_ID" />
</key-many-to-one>
<key-many-to-one name="organization" class="SgOrganization" >
<column name="ORGANIZATION_ID" />
</key-many-to-one>
</composite-id>
<property name="status" column="STATUS" type="char" access="field"/>
<!--
<many-to-one name="backend" column="BACKEND_ID" class="SgBackend"/>
<many-to-one name="organization" column="ORGANIZATION_ID" class="SgOrganization"/>
-->
<map name="defaultAttributes" lazy="true" table="SG_DEFAULT_ATTRIBUTE">
<!-- THIS IS INVALID!!!! -->
<key>
<column name="BACKEND_ID" />
<column name="ORGANIZATION_ID" />
</key>
<key column="ORGANIZATION_ID"/>
<index column="ATTR_NAME" type="string"/>
<element type="string" column="ATTR_VALUE" not-null="true"/>
</map>