This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Issue with MySql 5 FKs

 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic