-->
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.  [ 3 posts ] 
Author Message
 Post subject: CGLIB proxy and equals method
PostPosted: Thu Aug 18, 2005 1:05 pm 
Newbie

Joined: Wed Feb 23, 2005 11:57 am
Posts: 15
Hibernate version:3.1 Beta 2

Say I have this object:
Code:
public class ProviderType {
    protected long id;
    protected String desc;
...


With this equals method, uses a comparison of this.id and rhs.id

Code:
/**
     * @see java.lang.Object#equals(Object)
     */
    public boolean equals(Object object) {       
        if (object == this) { return true; }
        if (!(object instanceof ProviderType)) { return false; }
        ProviderType rhs = (ProviderType)object;
        return new EqualsBuilder().append(this.id, rhs.id).isEquals();
    }


When CGLIB has a proxy around it, rhs.id returns 0, whereas rhs.getId() returns the true id (which is not 0).

Changing the line to this:
Code:
return new EqualsBuilder().append(this.id, rhs.getId()).isEquals();

fixes it.

Has anyone seen this bug before, and know if this is an open issue with CGLIB?

Thanks,
gabe


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 1:10 pm 
Regular
Regular

Joined: Thu Dec 02, 2004 7:11 am
Posts: 85
http://forum.hibernate.org/viewtopic.php?t=946468


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 18, 2005 3:46 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
It is not a bug, but it is a proxy limitation. Proxy can intercept methods only and you must take it into acount.


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