Mapping Primary and Foreign Keys

Discussions

EJB programming & troubleshooting: Mapping Primary and Foreign Keys

  1. Mapping Primary and Foreign Keys (5 messages)

    Using WSAD 4.0.2 for NT, I am trying to map a CMP entity bean to an Oracle 9i table that has two primary keys that are also foreign keys in two other tables. Is this possible? Anybody tell me how? Thanks.
  2. two primary keys in a single table........?? or are u talking about composite primary keys
  3. Here's the DDL file used to create the table. Thanks for the response.

    CREATE TABLE "ITEM_INVENTORY"
      ("REPLENISH_QUANTITY" INTEGER,
       "MIN_THRESHOLD_LEVEL" INTEGER,
       "MAX_THRESHOLD_LEVEL" INTEGER,
       "AVAILABLE_QUANTITY" INTEGER,
       "DAYS_TO_REPLENISH" INTEGER,
       "LAST_MIN_THRESHOLD_DATE" DATE,
       "INSERT_UPDATE_USERID" VARCHAR2(10),
       "INSERT_UPDATE_TIMESTAMP" DATE,
       "INVENTORY_LOCATION_COMP_SKEY" INTEGER NOT NULL,
       "CUSTOMER_ITEM_SKEY" INTEGER NOT NULL);

    ALTER TABLE "ITEM_INVENTORY"
      ADD CONSTRAINT "SYS_C006899" PRIMARY KEY ("INVENTORY_LOCATION_COMP_SKEY", "CUSTOMER_ITEM_SKEY");

    ALTER TABLE "ITEM_INVENTORY"
      ADD CONSTRAINT "SYS_C006994" FOREIGN KEY ("INVENTORY_LOCATION_COMP_SKEY")
      REFERENCES "COMPANY"("COMPANY_SKEY")
      ON DELETE NO ACTION;

    ALTER TABLE "ITEM_INVENTORY"
      ADD CONSTRAINT "SYS_C006993" FOREIGN KEY ("CUSTOMER_ITEM_SKEY")
      REFERENCES "CUSTOMER_ITEM"("CUSTOMER_ITEM_SKEY")
      ON DELETE RESTRICT;
  4. Yes u can do it.
    Create a Primary Key class
    Class PK{

    }
  5. sorry for that incomplete reply
    class primarykey implements Serializable {
      public variable_PK1;
      public variable_PK2;
    //constr
    //over ride equals()
    // overide hashcode()
    // provide getter and setter methods to instance vaiables
    }

    in deployment descriptor files
    <ejb-jar>
    <enterprise-beans>
      <entity>
        <ejb-name>bean name</ejb-name>
        <local-home>Home</local-home>
        <local>Remote</local>
        <ejb-class>Bean</ejb-class>
    <prim-key-class>priamryKey</prim-key-class>
        <persistence-type>Container</persistence-type>

        <abstract-schema-name>..</abstract-schema-name>
        <sql-table-name>..</sql-table-name>

        <cmp-field>
          <field-name>..</field-name>
          <sql-name>..</sql-name>
        </cmp-field>
    ...
    ...
    ...
        <query>
            <query-method>
                <method-name>findAll</method-name>
            </query-method>
            <ejb-ql>....</ejb-ql>
        </query>
      </entity>
    </enterprise-beans>
    </ejb-jar>


    I hope this helps.
    If it does not then....
    http://www.caucho.com/support/resin-interest/0110/0365.html
  6. Thank you.