That is a little easier said than done.
It is our practice to always make a copy of a collection passed in from a setter or out through a getter. I don't have TOO much of a problem doing this for the setter, since our setters for collections are private (only exist for the persistence implementation). But I have a hard time passing the same instance out of a getter that we are refering to in our class. Someone could modify the contents, I have to make sure the collection is thread safe, etc... I am curious to know why I can't change the reference, if I'm just copying the data. I can't think of a good reason why hibernate would need to refer to the same instance, but I'm sure you have one. Could you suggest a workaround (i.e. create an immutable implementation of List and pass that to Hibernate; how would hibernate create an instance of that collection on retrieve.). Otherwise, I suppose we'll have to explictly delete orphaned objects. Thanks.
|