Search code examples
oraclehibernatejpanhibernate-mappinghibernate-onetomany

Hibernate one to many association deletion


In a one to many bidirectional association with cascade enabled as all-delete-orphan in hibernate, is there any possibility ever hibernate try to delete child entity using foreign key column? Its firing one extra query delete from child where foreign_key_col = parent_primary_key.


Solution

  • For bidirectional relation,if you delete casacade in the parent entity.

    You can remove the child from parent directly.

    //set parent as null
    child.setParent(null)
    
    //parent.children.iterater and remove it from the iterator.
    
    //then save the parent.
    save(parent)