1 Reply Latest reply on Dec 5, 2001 4:52 PM by Dain Sundstrom

    Deploying Entity Bean

    David Hickman Newbie

      I have a bean for an Individual:

      public IndividualPK ejbCreate( String forename,
      String surname,
      String department,
      String administrator,
      String controller)
      throws CreateException
      {
      this.forename = forename;
      this.middlename = "";
      this.surname = surname;
      this.department = department;
      this.administrator = administrator;
      this.budgetController = controller;
      username = forename.substring(0,1) +
      surname.substring(1);
      passwd = username;
      userCurrent = "Y";
      return null;
      }

      with a primary key class defined as:

      public class IndividualPK implements Serializable
      {
      public String username;
      public IndividualPK(String key)
      {
      this.username = key;
      }
      public IndividualPK()
      {
      }
      public String toString()
      {
      return username.toString();
      }
      public boolean equals(Object ind )
      {
      return ((IndividualPK)ind).username.equals(username);
      }
      }

      and an ejb-jar:

      Models an Individual
      <ejb-name>Individual</ejb-name>
      IndividualHome
      Individual
      <ejb-class>IndividualBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.String</prim-key-class>
      False
      <cmp-field><field-name>forename</field-name></cmp-field>
      <cmp-field><field-name>middlename</field-name></cmp-field>
      <cmp-field><field-name>surname</field-name></cmp-field>
      <cmp-field><field-name>username</field-name></cmp-field>
      <cmp-field><field-name>department</field-name></cmp-field>
      <cmp-field><field-name>administrator</field-name></cmp-field>
      <cmp-field><field-name>budgetcontroller</field-name></cmp-field>
      <cmp-field><field-name>passwd</field-name></cmp-field>
      <cmp-field><field-name>usercurrent</field-name></cmp-field>
      <primkey-field>username</primkey-field>


      However when I try to deploy this to the container I get an error message:
      The return type of ejbCreate must be the entity beans primary key type, ANY IDEAS?

        • 1. Re: Deploying Entity Bean
          Dain Sundstrom Master

          This line is wrong:

          <prim-key-class>java.lang.String</prim-key-class>


          It still won't work because your pk is missing a hashCode method. You must be very very very careful with the implementation of your pk class, or you will get weird error that are almost impossible to debug.

          I would recommend that you use a simple pk, like java.lang.String.