Say I have a model with a many to many or many to one relationship. This model would like this:
@Entity
public class A {
// other fields ...
@OneToMany(...)
private List<B> bEntities = new ArrayList<>();
}
There would be no reason to have a setter for this list but we would need a getter to be able to modify the list:
public List<B> getBEntities() { return bEntities; }
In this case, however, SpotBug is complaining about
EI_EXPOSE_REF: A.getBEntities() may expose internal representation by returning A.bEntities
I could map out the entire CRUD relationship into the model, like:
addB();
findBById();
// and so on and so forth
but not only would that still expose B entities, but also be out of the responsibility of the model as far as I understand. What is the proper way of doing this? Should I just suppress the warning for JPA managed entities?
B's key value is null.