Hi All,
I am getting a following error when trying to map hibernate collection:
Foreign key (media_group [media_owner_id])) must have same number of columns as the referenced primary key (Overview [prop_id,type_id,locale_code])
Is it possible to create such a mapping where only one primary key would be used for mapping one-to-many relationship through a config file instead implementing onLoad method from within POJO class? If so, how would I do it based on Hibernate mapping below. This involves hard coding some of the values and I would rather do it in the config file if possible.
The reason application requires such a mapping is because of generic database media framework design where media can be attached to any table identified by table name and primary key.
Hibernate mapping:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="Overview" table="overview" mutable="false">
<cache usage="read-only"/>
<composite-id>
<key-property name="propertyId" column="property_id" />
<key-property name="typeId" column="type_id" />
<key-property name="lang" column="locale_code" />
</composite-id>
<property name="title" column="title_name" />
<bag name="mediaList" where="media_owner_type_name='Overview'">
<key column="media_id"/>
<one-to-many class="Media" />
</bag>
</class>
<class name="Media" table="media" mutable="false">
<cache usage="read-only"/>
<composite-id>
<key-property name="ownerId" column="media_owner_id" />
<key-property name="ownerTypeId" column="media_owner_type_cd" />
<key-property name="mediaId" column="media_id"/>
</composite-id>
<property name="mediaName" column="media_name"/>
</class>
</hibernate-mapping>
Any advices or suggestions will be appriciated.
Thanks,
Dmitriy Frolov
|