Hibernate version: 3
Background: A registry can contain many registry items. So one registry maps to many registy items. I have spent over 6 hours today looking up how to solve the problem, but cannot find a solution.
Problem: This error message is recieved at runtime when I first try to create a SessionFactory:
Foreign key (FK2446A9D5E9C1910E:REGISTRY_ITEM [ITEM_ID])) must have same number of columns as the referenced primary key (REGISTRY_ITEM [REGISTRY_ID,ITEM_ID])
Here are my tables (MySQL 4.x):
Registry
Code:
CREATE TABLE `REGISTRY` (
`REGISTRY_ID` int(11) NOT NULL default '0',
`OWNER` varchar(50) NOT NULL default '',
`TITLE` varchar(50) NOT NULL default '',
PRIMARY KEY (`REGISTRY_ID`)
) TYPE=InnoDB
Registry Item
Code:
CREATE TABLE `REGISTRY_ITEM` (
`ITEM_ID` bigint(20) NOT NULL default '0',
`REGISTRY_ID` int(11) NOT NULL default '0',
`ITEM_NAME` varchar(200) NOT NULL default '',
`DESCRIPTION` text,
`IS_BOUGHT` int(1) NOT NULL default '0',
`WANT_FACTOR` int(1) default NULL,
PRIMARY KEY (`ITEM_ID`),
KEY `REGISTRY_ID` (`REGISTRY_ID`),
CONSTRAINT `REGISTRY_ITEM_ibfk_1` FOREIGN KEY (`REGISTRY_ID`) REFERENCES `REGISTRY` (`REGISTRY_ID`)
) TYPE=InnoDB
My two mapping files.
Registry
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.blakenetexpress.registry.registry.RegistryImpl" table="REGISTRY">
<id name="id" column="REGISTRY_ID" type="long">
<generator class="increment"/>
</id>
<property name="owner" column="OWNER" />
<property name="title" column="TITLE" />
<set name="items">
<key column="REGISTRY_ID" not-null="true"/>
<one-to-many
class="com.blakenetexpress.registry.registry.RegistryItemImpl"/>
</set>
</class>
</hibernate-mapping>
RegistryItem
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.blakenetexpress.registry.registry.RegistryItemImpl" table="REGISTRY_ITEM">
<id name="id" column="ITEM_ID">
<generator class="increment"/>
</id>
<property name="isBought" column="IS_BOUGHT" type="boolean"/>
<property name="itemName" column="ITEM_NAME" />
<property name="description" column="DESCRIPTION" />
<property name="wantFactor" column="WANT_FACTOR" />
<many-to-one name="registryId"
column="REGISTRY_ID"/>
</class>
</hibernate-mapping>
Thank you to anyone who can help. This has been driving me crazy! Oh yeah, please take it easy on me as I am probably considered a beginner-intermediate in DB, and a beginner at hibernate :-)