Hi Alvaro,
Besides people obtaining a safe way to implement these methods, they also
need to understand why these methods are necessary. hascode() and equals()
method are used by the hash containers (HashMap, HashSet, HashTable) to
provide faster access to the values in them. Such hash containers are used
by server implementation at different places.
A hash container determines a value (using some algorithm) based on the
hashcode of an Object. Different Objects with the same value are put in the
same bucket.
When a request is recieved by a hash container to access an Object, a hash
container uses same algorithm to determine a value and search for the Object
in a corresponding bucket. Objects in the bucket are compared with the
target object using equals() method.
So a good spread of hashes from the hashcode() method is really important to
enable fast access when writing user-defined primary key .
Hemant
www.pramati.com
----- Original Message -----
From: "Bo Xu" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, July 13, 2001 12:00 AM
Subject: Re: Class Primary Key
Alvaro Mota wrote:
> Hi
>
> "The EJBHome server requires a container-managed entity Bean to have a
> primary key class with a public primary key field (or fields, if using
> composite primary keys). You can have the container manage an enterprise
> Bean or write the code to manage the Bean yourself. In this example, both
> Beans are container-managed, and you should always let the container
manage
> an entity Bean.
> Here is the primary key class. The primary key in the Bonus table is
socsec,
> and so socsec is a public field in this class that is assigned a value
when
> the class is constructed.
>
> package com.ejbhome.examples;
>
> public class BonusPK implements java.io.Serializable {
> public int socsec;
>
> public BonusPK(int socsec) {
> this.socsec = socsec;
> }
>
> public BonusPK() {}
> }"
>
> when primary key have fields, is necessary implementation the methods :
> equals(), hashCode() and toString()?
>
> if necessary how make??
>
> thank very much
>
> �lvaro Mota Goncalves
> [...]
Hi :-) you can find the discussion about "equals()", "hashCode()",
"= =", "clone()" in the following:
- Joshua Bloch "Effective Java Programming Language Guide"(ISBN
0-201-31005-8)
- http://www.macchiato.com/
Bo
July 12, 2001
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff EJB-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".