-->
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.  [ 4 posts ] 
Author Message
 Post subject: Broken equals() implementations
PostPosted: Sun Oct 02, 2005 6:04 pm 
Newbie

Joined: Thu Sep 22, 2005 7:09 pm
Posts: 14
I'm having trouble with the equals() methods of my persistent object, shich seems to be a result of CGLIB enhancement. I'm not sure how to tell Hibernate to produce enhanced classes that don't break my code...

Here's a simplified example:

class Foo {
private String fooProp;
public String getFooProp() ...
public boolean equals(Object other) {
if (other == null) return false;
if (! other instanceof Foo) return false;
if (! fooProp.equals((Foo) other).fooProp) return false;
return true;
}
}

The problem is that, when other has been enhanced, other.fooProp is evaluating to null. other.getFooProp() returns the correct value, though.

So, short of rewritinging every line of code I have that references a field directly to use accessors, how do I fix this? Is there something I can configure to make the bytecode enhancement more robust?

L.

_________________
Laurie Harper
Open Source advocate, Java geek: http://www.holoweb.net/laurie
Founder, Zotech Software: http://www.zotechsoftware.com/


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 02, 2005 6:11 pm 
Senior
Senior

Joined: Thu Aug 04, 2005 4:54 am
Posts: 153
Location: Birmingham, UK
AFAIK you have to re-write everything to use accessors.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 02, 2005 9:00 pm 
Regular
Regular

Joined: Tue Mar 01, 2005 2:35 pm
Posts: 60
Use field access instead of property access.


Top
 Profile  
 
 Post subject: Doesn't seem to help
PostPosted: Mon Oct 03, 2005 8:11 pm 
Newbie

Joined: Thu Sep 22, 2005 7:09 pm
Posts: 14
OK, I just tried changing my mappings to use field access, and I'm seeing the same problem. I've tried setting default-access="field" on the <hibernate-mapping/> element, as well as access="field" on the individual <property/> elements, and the fields are still null.

Am I missing something? Is this the wrong way to specifiy field access?

Is there a way to specify the default globally (for all mappings)? I couldn't see anything in the Configuration section of the documentation about that.

Thanks,

L.

_________________
Laurie Harper
Open Source advocate, Java geek: http://www.holoweb.net/laurie
Founder, Zotech Software: http://www.zotechsoftware.com/


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