On 11/10/05, werner <[EMAIL PROTECTED]> wrote:

> Thanks for your answer. The hashCode function is a little mystery to me.
> I use a standard database setup where every table has a primary key
> (auto increment integer). Is it a proper solution to add the hashcode of
> all fields except the primary and return the result as the new hashcode
> of the object? What happens if I create 2 new objects with empty fields.
> They would always be considered as equal until I put some data into the
> object. So I think it wouldn't work.

The basic contract defined in java.lang.Object is that if two objects
are consided equal by the equals() method than they shall have the
same hash code (have a look at the javadoc of Object).
The method that I generally use is to use the hashcode builder from
commons-lang:

http://jakarta.apache.org/commons/lang/api/org/apache/commons/lang/builder/HashCodeBuilder.html

The basic usage pattern is that you append all fields to the builder
that you also use in the equals method.

Tom

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

Reply via email to