File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Lisa DeSouza
Greenhorn
Posts: 6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Discussion of similar issue
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
(It's not *directly* related, though, since they were using a composite key in the forum discussion you're referring to.)
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic