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.
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.