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
MrGomez
source share