• 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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

delete child rows using hibernate. (cascade?)

 
Ranch Hand
Posts: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all!

Suppose I have many-to-many relationship between question and test. Then I add some questions to a test.
So when I try to delete one of that questions, I get:
Cannot delete or update a parent row: a foreign key constraint fails (`sgc/test_question`, CONSTRAINT `FK75EC6E24266D1387` FOREIGN KEY (`questions_id`) REFERENCES `question` (`id`))

Is there some annotation to do this?
Does someone knows how can I manage do delete the child rows before delete the question?
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Leandro,

When you remove the Question, the Hibernate Session doesn't have knowledge of all entities (attached and detached) that has a reference to the removed Question.

You just has to remove the Question of Test manually.

 
Leandro Coutinho
Ranch Hand
Posts: 430
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks David!

well ... I still think that hibernate can do it for me xD. I have to learn how to use cascade annotation.
but meanwhile I did what you recomended and it is working.


override equals in question:
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic