Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Delete Problem

 
Manish Jain
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • 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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • 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
 
Rashid Darvesh
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic