>
> Can someone tell me why the primary key class must
> implement hashCode() and equals() method?

The container uses these method to find if a bean instance is in its cache
or not.
Think of the cache as a hash map of PrimaryKeys to EJB instances.

>
> How should I implement them?
>
As you would implement them for any value object:

class PrimaryKey {
    Type1 field1;
    Type2 field2;

    boolean equals(Object other) {
        if (other == null || !(other instanceof PrimaryKey)) return false;
        PrimaryKey o = (PrimaryKey)other;
        return (field1 == o.field1 || field1 != null &&
field1.equals(o.field1))
            && (field2 == o.field2 || field2 != null &&
field2.equals(o.field2))
    }

    int hashCode() {
        int ret = 0;
        if (field1 != null) ret += field1.hashCode();
        if (field2 != null) ret += field2.hashCode() * 127;
        return ret;
    }
}

- Avi
--
s/\be(\w+)/e-\1/g;

===========================================================================
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".

Reply via email to