On Jul 9, 2008, at 11:53 AM, syg6 wrote:


Sure enough it was a hashCode issue.

In the stack trace I had the following line:

com.myco.myapp.model.Request.hashCode(Request.java:418)

When I went to my hashCode method it looked pretty normal:

return new HashCodeBuilder().append(code).append(type) ...

The offending line was:

append(inspectionPacket)

What could be wrong with InspectionPacket? I didn't know. I took it out of
Request's hashCode() method and everything worked. Hmmm ...

I went to take a look at Request and sure enough my ManyToOne mapping for
InspectionPacket was bad:

@ManyToOne(fetch = FetchType.LAZY)

I have no idea why I made it Lazy. It's the only Association in my entire application mapped that way. All of my Associations (ManyToOne) are EAGER
and all of my Collections (OneToMany or ManyToMany) are LAZY.

Lesson learned. You get a Lazy Exception saying 'such-and-such a Collection could not be loaded' when it's a problem with a lazily-loaded Collection. Obviously. But when it's an Association, instead of saying 'Association
could not be loaded' it says 'no proxy'. Ok then.

I hope this helps someone, somewhere. It certainly cleared up a mystery for
me!

Bob             


I have hit 2 issues before where I've included Collections in my hashCode() and equals() - both Lazy Exceptions and NPE's.

I only include boxed primitive (String) properties + @Embedded properties when I write my hashCode() and equals(). Of course, if you have a property that you know should be unique - a natural key - in addition to your surrogate key, you can just use that one property as the basis of your hashCode() and equals() methods...

Getting hashCode() and equals() is really important (and not as easy as it seems!).. I've had a bunch of really weird errors bubble up further up the stack where I've gotten it wrong. I'd appreciate anyones thoughts on how to test those methods.

Alex


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to