Composite Primary Key in EJB 1.1 & Weblogic 5.1

Discussions

EJB programming & troubleshooting: Composite Primary Key in EJB 1.1 & Weblogic 5.1

  1. Is it true that we cannot use Composite Primary key when we opt for EJB 1.1 & Weblogic 5.1 as the development platform. If it is possible would anyone help in providing some direction to achieve my goal in developing a system, my database system would be on SQL.

    Murali Thantry
  2. It is possible to have a composite key in weblogic 5.1

    here is an example

    package com.whatever.whatever

    import java.io.Serializable;

    public class CompositePK implements java.io.Serializable {

      public int firstID;
      public int secondID;

      public CompositePK(){}
      
      public CompositePK( int firstID, int secondID ){
        this.firstID = firstID;
        this.secondID = secondID;
      }

      public boolean equals(Object obj){
        if (obj == null || !(obj instanceof CompositePK))
          return false;
        else if ( (((CompositePK)obj).firstID == firstID) &&
                  (((CompositePK)obj).secondID == secondID) )
         return true;
        else
          return false;
      }

      public int hashCode(){
        return toString().hashCode();
      }

      public String toString(){
        return firstID+""+secondID;
      }
    }