Let's say I have two entites like
{code:java}@ Entity Table (name = " Parent parent_entity ") @ Table Entity (name = " parent ParentEntity ") public class Parent ParentEntity extends PersistentEntity { @OneToOne(cascade = CascadeType.ALL) @ Transient JoinColumn(name = "inner_entity") private SomePOJO transient InnerEntity innerEntity = new InnerEntity() ;
public InnerEntity getInnerEntity() { return innerEntity; }
public void setInnerEntity(InnerEntity innerEntity) { this.innerEntity = innerEntity; } }
@ Table(name = "inner_entity") @Entity(name = "InnerEntity") public class InnerEntity extends PersistentEntity { @ OneToMany(mappedBy = " parent innerEntity ", cascade = CascadeType. All ALL , orphanRemoval = true) private List< Child ChildEntity > children = new ArrayList<>() ;
//getters, setters and other fields public List<ChildEntity> getChildren() { return children; }
public void setChildren(List<ChildEntity> children) { this.children = children; } }
@ Entity Table (name = " Child child_entity ") @ Table Entity (name = " child ChildEntity ") public class Child ChildEntity extends PersistentEntity { @ManyToOne @JoinColumn(name = "inner_entity") private Parent parent InnerEntity innerEntity ; @Column(name = "child_value") //getters, setters and other fields private String childValue; public InnerEntity getInnerEntity() { return innerEntity; }
public void setInnerEntity(InnerEntity innerEntity) { this.innerEntity = innerEntity; }
public String getChildValue() { return childValue; }
public void setChildValue(String childValue) { this.childValue = childValue; } } { code}
When I call session.update with parent entity, orphanRemoval does not have any affect. It does not delete child entity and relationship between parent and child |
|