-->
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: Lazy Loading - hashcode problem
PostPosted: Wed Jan 04, 2006 6:14 am 
Newbie

Joined: Wed Jan 04, 2006 5:29 am
Posts: 4
Hi there,

I also thought it would be handy indeed to have some comparison capabilities into my pojo's.

In fact, this kind of code looks like it could be templated.
That's how I ended up installing to Commonclipse plugin. It generates four you the equals & hashcode methods, bungin' all the prop's into a HashCodeBuilder (common-lang) of all properties of that pojo.

Keeping in mind that the db generated fields after persistence should be excluded from those methods, I generated the 2 methods above.

The situation (if it makes a difference); many-to-many using an association table.

When getting an instance of one end of the relation, I can retrieve all prop's.
But iterating over the Set to get to the other side of the relation ends up into
org.hibernate.LazyInitializationException: illegal access to loading collection

This seems to be caused by the implementation of the hashcode, that also takes collection (Set) into account and calling .append with it.
(See code snippet below)
Taking the collection out of the hashcode Commonclipse-generated method resolves the problem.
But equals should also take into account the contained collections when comparing!



Is there a way around this, or is the Commonclipse just not suitable for hibernate Pojo's ?
Can someone explain roughly, point me a link, anything the reason why hashcode causes this Lazy loading exception?

regards J.




Additional info:
==========
Hibernate version: 3.05
Full stack trace of any exception that occurs:
org.hibernate.LazyInitializationException: illegal access to loading collection
Name and version of the database you are using:mysql 4

public int hashCode() {
return new HashCodeBuilder(-1773935685, -1994585227)
.appendSuper(super.hashCode())
.append(this.solutions) // this is the Set; taking it out solves the probl.
.append(this.Clash)
.append(this.statusCode)
.append(this.serviceName).append(this.serviceInternalId).append(this.serviceId).append(this.filter)
.toHashCode();
}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 10:14 am 
Newbie

Joined: Mon Dec 27, 2004 3:47 pm
Posts: 12
check this out for help on hashCode() and equals()
http://www.hibernate.org/109.html


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.