This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes JDBC and Relational Databases and the fly likes Issue with MySql 5 FKs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "Issue with MySql 5 FKs" Watch "Issue with MySql 5 FKs" New topic

Issue with MySql 5 FKs

Kevin P Smith
Ranch Hand

Joined: Feb 18, 2005
Posts: 362
Hi guys

I have been having some trouble with MySql since it's upgrade and support of Foreign Keys. I have set up my Foreign Key in the tables

id (PK, Auto)

id (PK, Auto)
user_id (FK)

tbl_user_secure Foreign Keys has a reference setup linking it to

My Dao has the following:
@Table(name = "tbl_user_secure")
@SecondaryTable(name = "tbl_user_details", pkJoinColumns = @PrimaryKeyJoinColumn(name = "user_id"))

But when I try to create a new user I get the following:

Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException:
Cannot add or update a child row: a foreign key constraint fails
(`users`.`tbl_user_secure`, CONSTRAINT `tbl_user_secure` FOREIGN KEY (`user_id`) REFERENCES `tbl_user_details` (`id`))

Any advice?
I agree. Here's the link:
subject: Issue with MySql 5 FKs
It's not a secret anymore!