composite key problem


EJB programming & troubleshooting: composite key problem

  1. composite key problem (2 messages)

    I am getting problem with Composite key .How can i create class for it.
    I read following code from this forum few days back.

    public class ItemKey implements {
           public String productId;
           public String vendorId;

           public ItemKey() { };

           public ItemKey(String productId, String vendorId) {
             this.productId = productId;
             this.vendorId = vendorId;
           public String getProductId() {
              return productId;

          public String getVendorId() {
              return vendorId;
           public boolean equals(Object other) {
              if (other instanceof ItemKey) {
                 return (productId.equals(
                         && vendorId.equals(

              return false;

           public int hashCode() {
              return productId.hashCode();


    When using BMP and using following code to remove EJB Object there is problem ::

    publiv void ejbRemove() throws RemoteException
    ItemKey pk=(ItemKey)ctx.getPrimaryKey();
    String id1=pk.productId; //Problem Here
    String id2=pk.vendorID; //Problem Here
    delete from ItemTable where id=id1 and idd=id2

    Can anybody clarify me how to remove,... in case of composite key.
    What ctx.getPrimarykey() return in this case and what the value of pk will be.

    What in case of CMP

    Can anybody help me out in this case.Please send me code and other details of it.


    somal_sood at yahoo dot com

    Threaded Messages (2)

  2. composite key problem[ Go to top ]

    What is the error U r getting?? I couldn't see any wrong with Ur code. I did the same and it works fine.
  3. composite key problem[ Go to top ]

    In case of CMP the Container will read the contents of the primary and will issue a delete statement accordingly. U need not do anything.