Unable to add or update child row: foreign key constraint not satisfied

I have a user table that has desname as FK, referring to the descript table, I try to add desname to the user, but I gettng I can not add or update the child row: foreign key constraint does not allow the error to be executed.

desname is pre-populated, and I chose the same for the user. Where am I doing wrong? I use mysql and hibernate hbm

+6
java hibernate
source share
1 answer

The most common occurrence of this error is the inability to create (and save) the required instance of the object referenced by the foreign key. This usually happens when the create operation for the parent object is omitted, out of order, or in cases where the parent is not stored correctly in the database before trying to create your weak object.

For recording, this specific error message is only issued when Hibernate tries to write to the database (MySQL) to which it is connected. The sample code will greatly help here to solve your individual problem, as indicated in the comments.

For anyone who is interested, SO offers a lot of information for this particular error: https://stackoverflow.com/search?q=Hibernate+foreign+key+constraint+fails

+4
source share

All Articles