1 Reply Latest reply on Jan 29, 2002 3:43 PM by Dain Sundstrom

    cmr-field as part of compound primary key

    Bart Du Bois Newbie

      [Problem: equivalent with order-lineitem. If order is deleted, cmr-field of line-item is cleared which is part of line-item, so line-item gets useless]

      Hi,
      I have 3 domainObjects

      Patient:
      -id: String (PK)
      -name: String
      -password: String

      Medicine:
      -id: String (PK)
      -name: String

      Item:
      -patient_id: String
      -medicine_id: String
      -quantity: Long
      -sale_date: Long
      primary key ItemPK = {patient_id,sale_date}

      Now, I have 2 relations:

      Patient-Item: 1 Patient points to n Items (patient_id)
      Medicine-Item: 1 Medicine points to n Items (medicine_id)

      As this patient_id and medicine_id are both cmp- and cmr-fields, I am setting them as cmp-field in EJBCreate(...) first, and afterwards as cmr-field in EJBPostCreate(...)

      Pleaz note that I'm using cascade-delete from Patient to Item and from Medicine to Item

      Everything works great, except when I try to remove a Patient who has Items:
      -The patient is removed
      -The patient_id of all the Items of this patient are set to 0, what
      means that the primary key of these Items is changed and I can't do anything anymore with them.

      I can't believe that this is a unique setup. Do you guys have any ideas or suggestions?