2 Replies Latest reply on Dec 20, 2001 8:57 AM by pazu

    Deploying with Primary Key class

    simteq

      I am using JBoss 2.4.1a, when I deploy the EJB I get an error message that 'the primary key class must override hashCode()', can anyone help with the structure of this method?

      Thanks, Dave

        • 1. Re: Deploying with Primary Key class
          klaust

          try like this:

          public class anmeldungPK implements java.io.Serializable {

          public String man;
          public String ak;
          public String pnr;

          public anmeldungPK() { }

          public anmeldungPK(String man, String ak, String pnr) {
          this.man = man;
          this.ak = ak;
          this.pnr = pnr;
          }

          public boolean equals(Object other) {
          if( other instanceof anmeldungPK ) {
          return(
          man.equals(((anmeldungPK)other).man) && ak.equals(((anmeldungPK)other).ak) && pnr.equals(((anmeldungPK)other).pnr)
          );
          }
          return false;
          }

          public int hashCode() {
          return(
          man.hashCode() +
          ak.hashCode() +
          pnr.hashCode()
          );
          }

          public String toString() {
          return(man+"|"+ak+"|"+pnr);
          }
          }

          hope that helps

          • 2. Re: Deploying with Primary Key class
            pazu

            Take a look at Object.hashCode() javadoc. The short story: hashCode() should return a integer suitable to be used as key in a hash table.