I have a bean which is referred by many other beans.
@Entity
public class BeanA {
.....
}
@Entity
public class BeanB {
@ManyToOne
private BeanA beana;
}
public class BeanC {
@ManyToOne
private BeanA beana;
}
I want to block deletion of the BeanA objects if there is at least one reference to the object. And if there is a reference, the exception with human readable text shold be thrown (e.g. Cannot delete the object beacaure BeanC refers it).
It's possible to define @PreRemove method in BeanA, obtain EntityManager and execute many search queries. But this solution is too complex.
Is there any built in ejb3 functionality, which can help to solve this issue?