aspose file tools*
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
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Issue with MySql 5 FKs" Watch "Issue with MySql 5 FKs" New topic
Author

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

tbl_user_details
id (PK, Auto)
firstname
surname
email

tbl_user_secure
id (PK, Auto)
user_id (FK)
sername
password

tbl_user_secure Foreign Keys has a reference setup linking it to tbl_user_details.id

My Dao has the following:
@Entity
@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: http://aspose.com/file-tools
 
subject: Issue with MySql 5 FKs