title: How can I mark a foreign key constraint using Hibernate annotations?
body: <p>I am trying to use Hibernate annotation for writing a model class for my database tables.</p>
  
  <p>I have two tables, each having a primary key User and Question.</p>
  
  <pre><code>@Entity
  @Table(name="USER")
  public class User
  {
      @Id
      @Column(name="user_id")
      @GeneratedValue(strategy=GenerationType.AUTO)
      private Long id;
  
      @Column(name="username")
      private String username;
  
      // Getter and setter
  }
  </code></pre>
  
  <p>Question Table.</p>
  
  <pre><code>@Entity
  @Table(name="QUESTION")
  public class Questions extends BaseEntity{
  
      @Id
      @Column(name="question_id")
      @GeneratedValue(strategy=GenerationType.AUTO)
      private int id;
  
      @Column(name="question_text")
      private String question_text;
  
      // Getter and setter
  }
  </code></pre>
  
  <p>And I have one more table, UserAnswer, which has userId and questionId as foreign keys from the above two tables.</p>
  
  <p>But I am unable to find how I can reference these constraints in the UserAnswer table.</p>
  
  <pre><code>@Entity
  @Table(name="UserAnswer ")
  public class UserAnswer
  {
      @Column(name="user_id")
      private User user;
  
      //@ManyToMany
      @Column(name="question_id")
      private Questions questions ;
  
      @Column(name="response")
      private String response;
  
      // Getter and setter
  }
  </code></pre>
  
  <p>How can I achieve this?</p>