-->
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.  [ 6 posts ] 
Author Message
 Post subject: Collections under Hibernate
PostPosted: Thu Sep 16, 2004 5:25 pm 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
Hi,

According to http://www.hibernate.org/hib_docs/refer ... tions.html one should never store properties in subclasses such as HashMap. Rather "Map" should be used instead.

I've got the following line of code:

public Map getChildren()
{
return (Map) new HashMap(children).clone();
}

Is it possible this line of code causes problems for Hibernate? If so, is there a workaround for returning a copy of a HashMap instead of the original?

Thanks,
Gili


Top
 Profile  
 
 Post subject: Re: Collections under Hibernate
PostPosted: Thu Sep 16, 2004 5:36 pm 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
Ok, this issue seems related to the user of Collections under Hibernate. It seems to be caused by the fact that I return a clone() from Theme.getChildren(). Hibernate doesn't seem to like that. The question is, is there a way to return a clone() from getChildren()? "Good coding practices" call for returning either clones from getChildren() or a constant Map. The latter is not possible under Java. Is there no way to do this?

Thanks,
Gili


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 16, 2004 6:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You must not exchange the collection originally set by Hibernate against another instance. the get method should return exactly the collection which was handed to the set method


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 16, 2004 7:24 pm 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
michael wrote:
You must not exchange the collection originally set by Hibernate against another instance. the get method should return exactly the collection which was handed to the set method


Thanks Michael,

I was afraid you'd say that. So there is no way for me to protect my internal data from external users modifying it? Just curious.

Thanks,
Gili


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 17, 2004 7:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Let Hibernate access the field directly by using access=field, then you can do whatever you want in your get/set pair


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 17, 2004 9:26 am 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
michael wrote:
Let Hibernate access the field directly by using access=field, then you can do whatever you want in your get/set pair


Good idea. Thanks a lot!

Gili


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.