What is the standard way to access the collections used for bi-directional links (see
Hibernate Reference section 2.3.6)? I would like to prevent "everybody else from messing with the collections directly," but still need to be able to get all the elements of the collection. In the example in the reference, this isn't possible:
Code:
protected Set getEvents() {
return events;
}
protected void setEvents(Set events) {
this.events = events;
}
public void addToEvent(Event event) {
this.getEvents().add(event);
event.getParticipants().add(this);
}
public void removeFromEvent(Event event) {
this.getEvents().remove(event);
event.getParticipants().remove(this);
}
Do I need to return a read-only wrapper for the events getter and use field access to the set, or am I missing something obvious?
Ryan