Win a copy of Java Persistence with Spring Data and Hibernate this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Jeanne Boyarsky
Saloon Keepers:
  • Stephan van Hulst
  • Carey Brown
  • Tim Holloway
  • Piet Souris
Bartenders:

Cannot add or update a child row: a foreign key constraint fails JPA/Hibernate

 
Nicolas Allo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The application server is JBOSS 4 and I use JPA/HIbernate but the error is also present with JPA/TopLink.


I got a table " belong_to " who does the interaction between my cocktails and my categories of cocktails by referencing a line for a couple (cocktail/category)
A cocktail can have several categories and the inverse is also true.

The problem is present when i try to insert a line into "belong_to".

Of course, i want my architecture allows me in case i remove a cocktail, it will remove automatically each line of my table "belong_to" where my cocktail exists.
The same idea for my categories.


These are my 3 tables:



These are my 3 entities:








I got a mistake when i persist a CategoryCocktailId despite my entity is well formed
This is my test:




This is the error:



DOes someone has an idea to deal with this problem?

It should be a really common type of solution used to deal with interactif objects like this.?

Thank you very much




 
Mark Uppeteer
Ranch Hand
Posts: 159
Eclipse IDE C++ Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have a look at:

manytomany

it looks simpler than what you are doing.
 
Nicolas Allo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you!!

 
Nicolas Allo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what if i want to add a colum in my table "belong_to" a column whose the name is "quantity". Quantity depends of a cocktail and a category for example.
I don't find a solution..

Thank you.

 
Your buns are mine! But you can have this tiny ad:
The Low Tech Laboratory Movie Kickstarter is LIVE NOW!
https://www.kickstarter.com/projects/paulwheaton/low-tech
reply
    Bookmark Topic Watch Topic
  • New Topic