i am having a user table which has desname as FK referring to des table ,i am trying to add desname in user but i am gettng Cannot add or update a child row: a foreign key constraint fails error.
desname is prepopulated and i am selected the same for he user.Where i am doing wrong I ma using mysql and hibernate hbm
The most common occurrence of this error is failing to create (and store) the required instance of the entity referenced by the foreign key. This generally occurs when the create operation for the parent entity is omitted, out of order, or in cases where the parent isn't correctly stored in the database prior to attempting creation of your weak entity.
For the record, this specific error message is only emitted when Hibernate attempts to write to the (MySQL) database it's connected to. Example code would significantly help here for solving your individual problem, as pointed out in the comments.
For everyone else interested, SO offers plenty of information for this particular error: https://stackoverflow.com/search?q=Hibernate+foreign+key+constraint+fails
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With