Individual mapping using a composite key

The goal is to bind URLs.

Using the following 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;

This is a sleep mode mapping.

<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>

Purpose: Each unique url will have one entry in the "profiles" table. "Linked_profiles" refers to two URLs.

This leads to this exception.

org.hibernate.MappingException: displaying a broken column for: profile.id of: LinkedProfiles

Is this a defect in hibernate? See https://hibernate.atlassian.net/browse/HHH-1771

+4
source share
1 answer

A complex key means that if any of the component keys changes, it creates another unique key. Now consider the following:

 profiles:
id  |url     |
----|--------|
1   |someUrl |
2   |someUrl2|
3   |someUrl3|



linked_profiles:

profile  |linked    |
---------|----------|
1        |3         |->still a valid composite key
1        |2         |->still a valid composite key

, hibernate . , one-to-one Hibernate, Excepetion: org.hibernate.MappingException: broken column mapping. , one-to-one many-to-one, .

0