Hello Prince

If you have a primary key of String type you don't need to define a primary
key class, because java.lang.String
can be used as a primary key class.

If you insist on having your own PK class then override hashCode() and
equals() as follows in the code below:

public class MyPK implements java.io.Serializable
{
        private String pk; //primary key

        public MyPK() {};

        public MyPK(String pk)
        {
                this.pk=pk;
        }

        public void setPk(String pk)
        {
                this.pk=pk;
        }
        public String getPk()
        {
                return pk;
        }
        public int hashCode()
        {
                return pk.hashCode();
        }
        public boolean equals(Object another)
        {
        return ((MyPK)another).pk.equals(pk);
        }
}

Vano Beridze

-----Original Message-----
From: Prince Jacob Alex [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, 22. November 2000 17:52
To: [EMAIL PROTECTED]
Subject: Need help in PK Class


Hello,

   I am developing some sample EJB's using EJB ver 1.1 and weblogic as
the container. According to EJB 1.1 spec we need to override the methods
boolean equals() and int hashcode() in the PK class.

  My doubt is that if my primary key is a String, then how do I override
the method int hashCode(). I can cast the return as string but that
dosen't make much of sense.

Please let me know if I am missing something.

Thanks

Prince

===========================================================================
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".
Viruses are not found. Checked by AVP.

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