Hello -
I've got a one-to-many relationship between A and B. For each A, there can be 0 or many Bs. When I add a new B to the list, then call entityManager.merge(A), it works fine. The new B is also persisted in its own table. However, if I manipulate the list of Bs by removing a couple of the B records, then persist A as before, the Bs I removed from the list are not deleted from the B table.
I've tried overriding the "equals" and "hashcode" methods in my entity classes (Eclipse-generated), and have tried several approaches with the annotations, but I just can't get the B records to delete. It looks like maybe I need something like cascade=all, delete-orphan, but I can't find the equivalent to this using annotations. It seems like I'm so close, so maybe there's something easy I'm doing wrong. I'm pretty new to Hibernate, so maybe this is not the way it is supposed to work. Here's the relevant (pseudo)code:
In A:
Code:
@OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
@JoinColumn(name="aKey")
@OrderBy("bDate ASC")
getter for B
setter for B
In B:
Code:
@ManyToOne
@JoinColumn(name="aKey")
getter for A
setter for A
Any help would be appreciated.