Beginner |
|
Joined: Tue Feb 17, 2004 11:20 am Posts: 28
|
Hi
I'm reading your great book on Hibernate and I have a question.
Many times with my POJO object I want to return a collection which is unmodifiable so the caller cannot modify my internal collection. (he should call the POJOs corresponding add or remove for that)
Like I have a class
public class X
private ArrayList typeColl = new ArrayList();
// association methods
public Collection getTypeColl() {
return (Collection) Collections.unmodifiableCollection(typeColl);
}
public void setTypeColl(Collection pColl) {
typeColl.clear();
typeColl.addAll(pColl);
}
In the chapter 3 you say that The Collections are compared by identity.
and if the reference is changed there will be unnecessery updates etc.
in this version the reference has not been changed but your proxie would not work either as I'm not overwritting my internal reference :))
if I specify that the Collection should be accessed DIRECTLY, would that be a solution? or this idea of mine is not a good practise at all with hibernate ???
Thanks
Istvano
|
|