Thread:
 Easier implementation using commons-lang 
 thorstenschaefer   16 Jan 2004, 12:07 
 Re: Easier implementation using commons-lang 
 lhotari   16 Jan 2004, 13:20 
 Re: Easier implementation using commons-lang 
 RobJellinghaus   26 Feb 2004, 19:15 
 Re: Easier implementation using commons-lang 
 crbaker   20 Jul 2005, 02:15 

Comment
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
From: crbaker (20 Jul 2005, 02:15) Replies: 0, Views: 37590
Subject: Re: Easier implementation using commons-lang
On 16 Jan 2004 13:20, lhotari wrote:

>On 16 Jan 2004 12:07, thorstenschaefer wrote:

>>Hi,

>>The commons-lang package from apache contains builder for equals and
>>hashCode (beside others) which can be used for efficent and straight-
>>forward implementation of these methods.

>http://commonclipse.sourceforge.net/ is an eclipse plugin that generates
>code for commons-lang builders.

The only problem I've found with commonclipse is that its references
member fields rather than getters and setters which can cause the
following issue.

Problem occurs when referencing objects internal field values with
Hibernated proxies. As the equals method has access to these private
fields it is only natural to directly access the fields. The problem is
that hibernate proxies will only fetch the fields value on request from
the fields getter.
incorrect equals()

/**
     *  (at) see java (dot) lang.Object#equals(Object)
     */
    public boolean equals(Object object)
    {
        if (!(object instanceof User))
        {
            return false;
        }
        User rhs = (User) object;
        return new EqualsBuilder().append(this.username,  
rhs.username).isEquals();
    }

correct equals()

/**
     *  (at) see java (dot) lang.Object#equals(Object)
     */
    public boolean equals(Object object)
    {
        if (!(object instanceof User))
        {
            return false;
        }
        User rhs = (User) object;
        return new EqualsBuilder().append(this.getUsername(),
rhs.getUsername()).isEquals();
    }
Prev. thread 
 Next thread
 
Prev. posting 
 Next posting
© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]