-->
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.  [ 5 posts ] 
Author Message
 Post subject: proxy/hashCode/equals
PostPosted: Tue Nov 25, 2003 10:59 am 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Gavin (I hope you will read this), I found another source of ConcurrentModificationException in my code. It is nothing new - just another collection of proxied classes with equals() overriden.

Unfortunately I have spent alot of time before realizing this exception is caused by my simplest possible equals() implementation ( which only compares Ids ). Since Hibernate does not know how simple equals() is, it initializes object before invoking its equals().

As I understand, Hibernate's equals() implementation for proxied objects is exactly what I need - it compares Id properties. I would drop my equals/hashCode and sleep well, but I need to compare objects later (that part is not related to Hibernate). And moreover - not all my objects come from database, some are just transient instances. That is why I'm keeping my equals().

But presence of this equals() not only causes exceptions (which I suppose is already fixed), but makes the code inefficient - now Hibernate initializes all elements in the collection just to insert new one.

Sorry for such a long explanation.

What do I want? Actually, I do not know. Currently I have only one idea - additional attribute for the <class> element which tells Hibernate what class has equals/hashCode which do not require full initialization.

I would make a enchancement request on JIRA if I only knew what to request :) And I hope you have a better idea than my...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 11:03 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Why don't you just try using a <bag> instead of a <set>.

Mind you, I have never, ever had a problem with this in practice, so I'm not sure why its so problematic for you.

But anyway, I fixed the ConcurrentModification problem in CVS ... why not just wait till anon cvs is up to date.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 11:30 am 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Hmm... I though <bag> is collection which allows duplicate entries. In my case, duplicates are not allowed.

Yes, I know you already fixed the exception, but Hibernate still need to initialize all elements in the collection in order to insert another. This is not efficient for large collections.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 11:37 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Hi,

as I understand there is no way to avoid initializing the Set because the Set-API states .add(object) has to return false if the added object was allready contained in the set. So initialization is necessary for API confomance. See http://www.hibernate.org/hib_docs/reference/html/collection-performance.html#collection-performance-mostefficient-2


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 25, 2003 12:18 pm 
Expert
Expert

Joined: Tue Sep 16, 2003 4:06 pm
Posts: 318
Location: St. Petersburg, Russia
Yeah but what is "object is already in set"? That means "the same object" And this means "the object for which equals() returns true".

Hibernate proxy implements equals() by comparing Id properties _without_ initializing all other properties of the the object. That means equality check does not force request to database.

But it you override equals() method, proxy just can not perform Id comparison - it MUST let you code to compare objects. But your equals() may access eny properties it wants and Hibernate does not know which. That is why, proxy initializes (loads) object before invoking its equals().


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