JPA/hibernate - Cannot add or update a child row: a foreign key constraint fails - BUT record exists

☆樱花仙子☆ 提交于 2019-12-06 11:20:18

You have to mention the @JoinColumn

@ManyToOne
@JoinColumn(name = "company_id")
private Company company;

This is responsible for creating the company_id on the Event table.

nogridbag

I narrowed the problem down and posted another question here:

JPA/Hibernate - Entity name seems to be important. If I rename to "Bob" works fine

I found the solution here:

http://developmentality.wordpress.com/2011/05/23/hibernate-mysql-mac-foreign-key-nightmares-a-painless-solution-to-a-painful-problem/

Due to the combination of mysql, hibernate, and mac os x, there's some issue where you have to use a lowercase naming strategy in hibernate. Hibernate by default uses a camel case naming strategy.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!