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

Hibernate Delete Problem

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am very new to the hibernate and I am facing some problem while deleting an object.
I have two tables : one is Person and other is Charge and their mapping is as follows:


The problem I am facing with this is when i delete the person, the charge should also be deleted. But only person gets deleted not the charge. Can anyone please help me out how we can do this.

I will really appreciate if anyone can solve this problem.

Manish Jain
SCJP1.4
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want all the charges to be deleted when you delete a person, then you need to map a one to many from Person to Charges, and you must use cascade options. I suggest, "all, delete-orphan"

cascading is what determines how the related objects either get updated, inserted or deleted, when save is called on the main object.

I suggest reading up on cascade options at the hibernate website to fully understand what it means. It is a huge important concept to understand with Hibernate.

Mark
 
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have a look at this tutorial. there is an example there on how to cascade delete
http://www.makemyinfo.com/Tutorial.do?action=getTutorial&tutId=T0005.jsp

Rashid
 
We're being followed by intergalactic spies! Quick! Take this tiny ad!
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic