aspose file tools*
The moose likes Object Relational Mapping and the fly likes Foreign key must have same number of columns as the referenced primary key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Foreign key must have same number of columns as the referenced primary key" Watch "Foreign key must have same number of columns as the referenced primary key" New topic
Author

Foreign key must have same number of columns as the referenced primary key

Lisa DeSouza
Greenhorn

Joined: Jul 21, 2009
Posts: 6
I get this error every time I try to compile...
Caused by: org.hibernate.MappingException: Foreign key (prd_id:product [prvd_prd_id])) must have same number of columns as the referenced primary key (product_vendor_details [ven_id,prvd_vendor_id])

Can someone please explain? Thanks in advance

Vendor table and xml:
CREATE TABLE `vendor` (
`ven_id` bigint(20) NOT NULL AUTO_INCREMENT,
`ven_clinic_id` bigint(20) DEFAULT NULL,
`ven_name` varchar(20) NOT NULL,
`ven_address` varchar(100) NOT NULL,
`ven_city` varchar(30) NOT NULL,
`ven_state` varchar(30) NOT NULL,
`ven_country` varchar(30) NOT NULL,
`ven_pin` int(11) NOT NULL,
`ven_web_site` varchar(30) DEFAULT NULL,
PRIMARY KEY (`ven_id`),
KEY `FK_vendor` (`ven_clinic_id`),
CONSTRAINT `FK_vendor` FOREIGN KEY (`ven_clinic_id`) REFERENCES `client` (`clt_clinic_id`)
)


Vendor Contact table & xml:

Create Table

CREATE TABLE `vendor_contact_details` (
`vcd_id` bigint(20) NOT NULL AUTO_INCREMENT,
`vcd_vendor_id` bigint(20) DEFAULT NULL,
`vcd_title` varchar(5) DEFAULT NULL,
`vcd_name` varchar(20) DEFAULT NULL,
`vcd_phone` varchar(20) DEFAULT NULL,
`vcd_ext` int(11) DEFAULT NULL,
`vcd_remarks` varchar(100) DEFAULT NULL,
`vcd_email_id` varchar(50) DEFAULT NULL,
PRIMARY KEY (`vcd_id`)
)


Product table & xml:
CREATE TABLE `product` (
`prd_id` bigint(20) NOT NULL AUTO_INCREMENT,
`prd_clinic_id` bigint(20) DEFAULT NULL,
`prd_name` varchar(20) DEFAULT '',
`prd_description` varchar(100) DEFAULT NULL,
PRIMARY KEY (`prd_id`),
KEY `FK_product_clinic_id` (`prd_clinic_id`),
CONSTRAINT `FK_product_clinic` FOREIGN KEY (`prd_clinic_id`) REFERENCES `clinic` (`cln_id`)
)
REATE TABLE `product_vendor_details` (
`prvd_id` bigint(20) NOT NULL AUTO_INCREMENT,
`prvd_prd_id` bigint(20) NOT NULL,
`prvd_vendor_id` bigint(20) NOT NULL,
`prvd_qty` int(11) NOT NULL,
`prvd_cost_price` double NOT NULL,
`prvd_selling_price` double NOT NULL,
`prvd_weight` double NOT NULL,
`prvd_tax` double NOT NULL,
`prvd_available_qty` double NOT NULL,
`prvd_usage_type_id` bigint(20) NOT NULL,
`prvd_threshold` double NOT NULL,
`prvd_expiry_date` date NOT NULL,
`prvd_prd_unit_id` bigint(20) NOT NULL,
PRIMARY KEY (`prvd_id`),
KEY `FK_product_vendor_details_product` (`prvd_prd_id`),
KEY `FK_product_vendor_details_vendor` (`prvd_vendor_id`),
CONSTRAINT `FK_product_vendor_details_product` FOREIGN KEY (`prvd_prd_id`) REFERENCES `product` (`prd_id`),
CONSTRAINT `FK_product_vendor_details_vendor` FOREIGN KEY (`prvd_vendor_id`) REFERENCES `vendor` (`ven_id`)
)
Amit Vinod Dali
Ranch Hand

Joined: Apr 14, 2010
Posts: 42
Discussion of similar issue
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

(It's not *directly* related, though, since they were using a composite key in the forum discussion you're referring to.)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Foreign key must have same number of columns as the referenced primary key