This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC 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 Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
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?
Consider Paul's rocket mass heater.
subject: Issue with MySql 5 FKs
Similar Threads
Exception in Deleting Parent and Child entity
Foreign Keys
hibernate table mapping
insert new parent/child row. How to handle new primary/foreign key inserts
AutoIncrement primaryKey