Consider two entities:
@Entity
public class A implements Serializable {
...
@OneToMany(mappedBy = "a", orphanRemoval = true)
@Cascade(CascadeType.ALL)
@JsonManagedReference
private List<B> bs = new ArrayList<B>();
...
}
@Entity
public class B implements Serializable {
...
@ManyToOne
@JsonBackReference
private A a;
...
}
I'm receiving a JSON representation of A and loading it via a @RequestBody in one of my Spring controllers (in this case this is an existing entity that already has an identifier; the following issue does not apply to new entities).
As you might expect, calling session.saveOrUpdate does not auto-magically remove any B's (from the database) that were not in the deserialized A.bs collection. Additions to the collection do work, as do updates of individual entities in the collection.
What is the proper way to remove these objects? Does the request have to be structured differently for this to work? (Using Spring 3.1.1 / Hibernate 4.0.1)