Consider you have an entity Entity with the following unidirectional relationship:
@ManyToMany
private Set<OtherEntity> setOfOtherEntities;
public Set<OtherEntity> getOtherEntities() {
if (setOfOtherEntities == null) {
setOfOtherEntities = new TreeSet<OtherEntity>();
}
return setOfOtherEntities;
}
Now consider a number of OtherEntities are removed from the database. What happens with the numerous TreeSets for all the existing Entities in the database? Are OtherEntities that are referenced in a TreeSet automatically removed as well, so, the TreeSet is reduced in size? Or do I end up having a number of null pointers in the Sets?
Would I need to manually go through all Entities in the database to check if there's a TreeSet where an entry points to an to-be-removed OtherEntity, to remove it from the Set manually? Hope not...
Thanks for your help!
Best regards, Benjamin