Hi,
I'm trying to map a collection (of type map) using a foreign key and a fixed value as the key/mapping arguments.
I have several tables of product types and a language table which holds stuff like product names and so on.
Now let's say we have an Accessory table which holds (obviously) accessories, then the name of an accesory is stored in the language table with language.id = accessory.id and language.type='accessory'. The map-key should be the language.lang field, a language-code string.
Now, no matter what I've tried, I just can't get the "language.type='accessory'" part right, doesn't like multiple key element, which in turn wouldn't allow elements anyways.
I've also tried it with a composite component as foreignKey, with the constant set by default, but that didn't really work either:
<class name="AccessoryTypes"
table="accessorytypes">
<id name="id" column="id" type="java.lang.Long" unsaved-value="0">
<generator class="identity"></generator>
</id>
<map name="Name" table="ProductCode">
<key column="CompositeId" />
<map-key column="Language" type="string" />
<one-to-many class="ProductCode" />
</map>
</class>
<class name="Language"
table="Language">
<composite-id name="compositeId" class="languageKey">
<key-property name="Type"></key-property>
<key-property name="Id"></key-property>
</composite-id>
<property name="Lang" type="string"></property>
<property name="Value"></property>
</class>
of course with the appropriate classes. This approach gives no error, but doesn't fill the HashMap of the Accessory class either...
any help would be appreciated, thanks.
[edit] I now tried it with property-ref as ziodberg suggested, first with a not with like this:
<class name="AccessoryTypes"
table="accessorytypes">
<id name="id" column="id" type="java.lang.Long" unsaved-value="0">
<generator class="identity"></generator>
</id>
<properties name="CompositeId" >
<property name="id" />
<property name="Type" formula="'accessory'" />
</properties>
<map name="Name" table="ProductCode">
<key property-ref="CompositeId" />
<map-key column="Language" type="string" />
<one-to-many class="ProductCode" />
</map>
</class>
and
<class name="com.swissclick.wesco.web.model.ProductCode"
table="ProductCode">
<composite-id class="com.swissclick.wesco.web.model.ProductCodeKey" mapped="true">
<key-property name="Type"></key-property>
<key-property name="id"></key-property>
</composite-id>
<property name="Language" type="string"></property>
<property name="Value"></property>
</class>
but this doesn't work, either, it gives
org.hibernate.MappingException: collection foreign key mapping has wrong number of columns: AccessoryTypes.Name type: component[Id,Type]
which doesn't turn up any helpful information on google.
any ideas?