目的は、URL を関連付けることです。
次のSQLを使用して、
CREATE TABLE `profiles` (
`id` serial ,
`url` varchar(256) ,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `linked_profiles` (
`profile` bigint unsigned references profiles(id),
`linked` bigint unsigned references profiles(id),
PRIMARY KEY (`profile`, `linked`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
これが休止状態のマッピングです。
<hibernate-mapping>
<class name="LinkedProfiles" table="linked_profiles">
<composite-id>
<key-property name="profile" column="profile" type="long" />
<key-property name="linked" column="linked" type="long" />
</composite-id>
<one-to-one name="profile" class="Profile" cascade="save-update">
</one-to-one>
<one-to-one name="linked" class="Profile" cascade="save-update">
</one-to-one>
</class>
<class name="Profile" table="profiles">
<id name="id" type="long">
<column name="id" not-null="true"/>
<generator class="identity"/>
</id>
<property name="url" type="java.lang.String">
<column name="url"/>
</property>
</class>
</hibernate-mapping>
目的: すべての一意の URL には、「プロファイル」テーブルに 1 つのエントリが含まれます。「linked_profiles」は 2 つの URL を関連付けます。
これにより、この例外が発生します。
org.hibernate.MappingException: 次の列マッピングが壊れています: profile.id of: LinkedProfiles
これは Hibernate の欠陥ですか? https://hibernate.atlassian.net/browse/HHH-1771を参照してください。