• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate Mapping : delete children in one to many bidirectional mapping in hibernate

 
koushik Rock
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a parent object and its detail object. The mappings are mentioned in the below code -
Parent Object Mapping



Child Object mapping



I am able to save a new parent with say 3 childrens.
Now, in the update operation,

In parent.childSet, I am removing all values and setting new values.
When I do session.update(parent), my requirement is to,

1. Delete all the existing children for the parent - as the parent.childSet doesn't have them.
2. Insert the new values that are available in parent.childSet.

here, parent.childSet means, the Set in Parent Class/HBM Mapping.

The problem happening now is,

1. It is throwing exception - "cannot insert NULL into ("CHILD"."PARENT_ID")"

I will keep updating the question if it is not clear.

Thanks for your time!
 
Amritendu De
author
Ranch Hand
Posts: 188
11
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This can be achieved with orphanRemoval=true. You can see detailed code given in my book.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic