Hello,
Hibernate 3.3
EntityManager & Annotations 3.4
We have the following entities:
Code:
@Entity
public class A {
@Id
private Long id;
@OneToMany(mappedBy = "a", cascade = ALL, fetch = LAZY)
@Cascade(DELETE_ORPHAN)
private List<B> bList = new ArrayList<B>();
}
@Entity
public class B {
@Id
private Long id;
@ManyToOne(cascade = ALL, fetch = EAGER)
private A a;
@ManyToOne(fetch = LAZY, optional = false)
@JoinColumn(name = "C_ID", nullable = false)
private C c;
}
@Entity
public class C {
@Id
private Long id;
}
A -> B is a composition: A is the owner of all Bs.
B -> C is an aggregation: Cs can exist without Bs, however each B cannot exist without a C
In one use case, we have the following objects which are retrieved from the database: a1 -> {b1} and b1 -> c1. We try to remove c1, then remove b1 from a1:
Code:
entityManager.remove(c1);
a1.remove(b1);
Whatever we try, the EntityManager tries to set b1.c to null before deleting it. It seems to me that deleting b1 and then deleting c1 would work. Why is the EntityManager not doing this?
Thank you.