The moose likes Object Relational Mapping and the fly likes Hibernate Delete Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Hibernate Delete Problem" Watch "Hibernate Delete Problem" New topic
Author

Hibernate Delete Problem

Manish Jain
Ranch Hand

Joined: Jun 07, 2005
Posts: 30
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

Joined: Feb 05, 2001
Posts: 16622

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Rashid Darvesh
Ranch Hand

Joined: Feb 13, 2004
Posts: 189
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
 
IntelliJ Java IDE
 
subject: Hibernate Delete Problem
 
Threads others viewed
Hibernate generating queries with duplicate columns
Hibernate Mapping (Many-To-One Association). Problem. This forum is my last hope.
Hibernate 3.0
Hibernate Cascade
removing a child
Two Laptop Bag