-->
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: Book contradiction: "encapsulate collections" vs dirty check
PostPosted: Tue Jul 07, 2009 11:33 am 
Newbie

Joined: Tue Jul 07, 2009 11:18 am
Posts: 5
Location: Newton, MA
I am reading "Java Persistence with Hibernate", 2007 edition. Chap 3 page 119 says:

Quote:
You should consider the static methods Collections.unmodifiedCollection(c) and Collections.unmodifiableSet(s), if you prefer to wrap the internal collections before returning them in your getter method.


on page 122 it says:

Quote:
Collections are compared by identity! For a property mapped as a persistent collection, you should return exactly the same collection instance from the getter method that Hibernate passed to the setter method. If you don't, Hibernate will update the database, even if no update is necessary, every time the state held in memory is synchronized with the database.


Given the response to this posting: https://forum.hibernate.org/viewtopic.php?t=938019, it appears that the latter quote supersedes the former. Am I right in interpreting this to mean you can't really encapsulate collections and control their access under Hibernate?

Thanks.


Top
 Profile  
 
 Post subject: Re: Book contradiction: "encapsulate collections" vs dirty check
PostPosted: Tue Jul 07, 2009 4:51 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Returning an unmodifiable collection implies that you do not have a setter method, of course. How additions and removals are then best handled is explained in chapter 3 as well. It should be obvious that you then do not have to worry about identity comparison because you never replace the collection instance. That's actually the whole point...

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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.