> -----Original Message-----
> From: Bo Xu [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, November 23, 2000 3:55 PM
> To: [EMAIL PROTECTED]
> Subject: Re: Need help in PK Class
>
>
> Anil Rawlani wrote:
>
> > Hello Prince,
> >
> > In primary class files  hashcode method
> > public int hashCode()
> > {
> >
> >         return  variablename.hashcode();
> > }
> >
> > and add one more method in same class
> >
> > public String toString()
> > {
> >         variablename.toString();
> > }
> >
> > and try compliling it , I think that this will solve the problem
> >
> > bye!!!!!!!1
> >
> > With regards,
> >
> > Anil S. Rawlani,
> > Global Tele-Systems Ltd,
> > Phone: 7612929, 7684111 Ext:3271.
> >
> > > -----Original Message-----
> > > From: Prince Jacob Alex [SMTP:[EMAIL PROTECTED]]
> > > Sent: Wednesday, November 22, 2000 7:22 PM
> > > 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
> > >
>
> [...]
>
> Hi :-)  perhaps we also need to override equals method , the following
> is basicly from the book *Mastering Enterprise JavaBeans ...*
> (ISBN: 0-471-33229-1)
>
>
> public class AccountPK implements java.io.Serializable
> {
>   public String accountID;
>
>   public AccountPK(String accountID) {
>   this.accountID = accountID;
>   }
>
>   public AccountPK() {
>   }
>
>   public String toString() {
>  return accountID.toString();
>   }
>
>   public int hashCode()
>   {
>      return accountID.hashCode();
>   }
>
>   public boolean equals(Object acct)
>   {
>      return ((AccountPK)acct).accountID.equals(accountID);
>   }
> }
>

the equals method should look like this:

public boolean equals(Object obj){
  if (obj==null ||!(obj.instanceOf(AccountPk)))
    return false;
  else {
    return ((AccountPk)obj).accountID.equals(accountID);
  }
}

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