-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Return different collection instance on getter methods
PostPosted: Thu Jan 20, 2005 12:51 pm 
Beginner
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 20, 2005 1:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
accessing it directly will solve your problem yes.

_________________
Max
Don't forget to rate


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.