Pages 70-71 talk about the importance of ensuring POJO association correctness, and present the addChildCategory() convenience method. It goes on to explain:
Quote:
Because we would like the addChildCategory() to be the only externally visible mutator method for the child categories, we make the setChildCategories() method private. Hibernate doesn’t care if property accessor methods are private or public, so we can focus on good API design.
That's great, but what prevents someone from mistakenly adding a child by using the Collection's add() method instead of the addChildCategory() method? That is, couldn't they just do exactly what's presented on page 70?:
Code:
aParent.getChildCategories().add(aChild);
The child gets added, but its parent won't get set and it won't get removed from its previous parent's collection (if any).
Thanks and sorry if I'm just being dumb and missing something obvious.