1 Reply Latest reply on Feb 24, 2007 10:34 PM by Lu Li

    Composite Key is made up by foreign keys

    Lu Li Newbie

      Hi all,

      I have problem finding out how to specify the member of the composite key are foreign keys pointing to primary key of other tables.
      For example, If my composite key have 2 columns (A,B). I created wrapper like
      public final class CompKey implements Serializable {
      private int A;
      private int B;

      public boolean equals(Object obj) {
      ..............
      }
      public int hashcode() {
      ...........
      }
      }

      Then in my class I will use
      @IdClass(CompKey.class)
      @Entity
      public class MyClass implements Serializable{
      private int A;
      private int B;

      }



      But now I want to specify A and B as foreign keys, how do I do that? I tried using @JoinColumn and add 2 more fields to class MyClass but that gives me error saying the column names A and B are repeated.


      Can someone tell me how to specify A and B as foreign key but can still use them as composite key at the same time?


      Thank you very much in advance,
      Lngo