title: How to model a friendship relationship in hibernate?
body: <p>I need to have a friendship relationship. I have a friendship class with two primary keys that each is a Member class. I am receiving following exception:</p>
  
  <pre><code>org.hibernate.MappingException: Foreign key (FK_8ynretl1yt1xe3gcvfytrvpq:Friendship [])) must have same number of columns as the referenced primary key (Member [username])
  </code></pre>
  
  <p><strong>Friendship</strong></p>
  
  <pre><code>@Entity
  public class Friendship implements Serializable {
      /**
       * 
       */
      private static final long serialVersionUID = -1234656876554786549L;
      @Id
      @ManyToOne
      Member requester;
      @Id
      @ManyToOne
      Member friend;
      @Temporal(javax.persistence.TemporalType.DATE)
  Date date;
  </code></pre>
  
  <p><strong>Member</strong></p>
  
  <pre><code>@Entity
  public class Member {
      @Id
      @MapsId
      @OneToOne(cascade = CascadeType.ALL)
      @JoinColumn(name = "username")
      Credential credential;
      @Column(nullable = false)
      String fname;
      @Column(nullable = false)
      String lname;
      @Column(nullable = false)
      short gender;
  </code></pre>
  
  <p><strong>Credential</strong></p>
  
  <pre><code>@Entity
  public class Credential {
      @Id
      @Column(nullable = false, unique = true)
      private String username;
      @Column(nullable = false)
      private String password;
      @Column(nullable = false)
      private String authority;
      @Column(nullable = false)
      private boolean enabled;
  </code></pre>