Hi,
I am getting the following error when am trying to run my application( using MySql database). Here I am using parent table's composite unique key as a child table's composite foreign key.
Foreign key (FK7E46806589B41CD9:ct_bill_of_material [MATERIAL_NUMBER,SAAS_ORG_KEY])) must have same number of columns as the referenced primary key (ct_material [MATERIAL_KEY])
My db scripts for the parent(ct_material) and chils(ct_bill_of_material) as follows. (unnecessary columns ignored)
ct_material CREATE TABLE `ct_material` (
`MATERIAL_KEY` decimal(12,2) NOT NULL,
`MATERIAL_NUMBER` varchar(32) NOT NULL,
`SAAS_ORG_KEY` decimal(12,0) NOT NULL,
`MATERIAL_TYPE` varchar(10) default NULL,
PRIMARY KEY (`MATERIAL_KEY`), UNIQUE KEY `MATERIAL_NUMBER` USING HASH (`MATERIAL_NUMBER`,`SAAS_ORG_KEY`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8
ct_bill_of_material CREATE TABLE `ct_bill_of_material` (
`BOM_NUMBER` varchar(12) NOT NULL,
`BOM_VERSION` varchar(5) NOT NULL,
`SAAS_ORG_KEY` decimal(12,0) NOT NULL,
`MATERIAL_NUMBER` varchar(32) NOT NULL,
PRIMARY KEY (`BOM_NUMBER`,`BOM_VERSION`),
CONSTRAINT `ct_bill_of_material_ibfk_2` FOREIGN KEY (`MATERIAL_NUMBER`, `SAAS_ORG_KEY`) REFERENCES `ct_material` (`MATERIAL_NUMBER`, `SAAS_ORG_KEY`),
) ENGINE=InnoDB DEFAULT CHARSET=utf8
and mapping file is like:
<class name="CtMaterial" table="ct_material">
<id name="materialKey" type="java.math.BigDecimal" column="MATERIAL_KEY">
<generator class="assigned" />
</id>
<property name="materialNumber" type="java.lang.String" column="MATERIAL_NUMBER" not-null="true" length="32"/>
<property name="saasOrgKey" column="SAAS_ORG_KEY" type="java.math.BigDecimal" length="12" not-null="true"/>
<property name="materialType" type="java.lang.String" column="MATERIAL_TYPE" not-null="true" length="32"/>
<set name="ctBillOfMaterials" lazy="true" inverse="true"cascade="save-update">
<key>
<column name="MATERIAL_NUMBER" />
<column name="SAAS_ORG_KEY" />
</key>
<one-to-many class="CtBillOfMaterial"/>
</set>
</class>
<class name="CtBillOfMaterial" table="ct_bill_of_material">
<composite-id name="comp_id" class="CtBillOfMaterialPK">
<key-property name="bomNumber" column="BOM_NUMBER"
type="java.lang.String" length="12"/>
<key-property name="bomVersion" column="BOM_VERSION"
type="java.lang.String" length="5"/>
</composite-id>
<many-to-one name="ctMaterial" class="CtMaterial"
not-null="true">
<column name="MATERIAL_NUMBER" />
<column name="SAAS_ORG_KEY" />
</many-to-one>
</class>
I am tried with unique-key(composite) declaration in the parent(ct_material) and used that key in the child's <many-to-one> also but still it is giving the same error.
am i doing in the right way?
Could you please give me any suggestion??
Thanks,
Kiran Rredy A
|