I am using Eclipselink as a JPA provider and using EntityListener to catch preRemove events from my entities. I have the following hierarchy:
@Entity
@Table(name = "MY_ENTITY")
@EntityListeners(AuditListener.class)
public class MyEntity {
.....
@OneToMany(mappedBy = "myEntity", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<AnotherEntity> anotherEntities;
.....
}
@Entity
@EntityListeners(AuditListener.class)
@Table(name="ANOTHER_ENTITY")
public class AnotherEntity {
@MapsId("idMyEntity")
@ManyToOne
@JoinColumn(name = "ID_MY_ENTITY")
private MyEntity myEntity;
}
The problem is when I remove one entry from anotherEntities Set and call update for myEntity from JPA, the method public void preUpdate(DescriptorEvent event) gets called for entity 'MyEntity' and thats allright, but as it cascades to 'AnotherEntity' entity and it gets deleted (as it should) there is no call to preRemove(DescriptorEvent event) method for AnotherEntity and I need to know when this occurs.
Is there any annotation missing here ? Do I need to call directly the remove for 'AnotherEntity' to get a callback working ? Thanks in advance.