I am trying to use Hibernate annotation for writing a model class for my database tables.
I have two tables, each having a primary key User and Question.
@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
}
Question Table.
@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
}
And I have one more table, UserAnswer, which has userId and questionId as foreign keys from the above two tables.
But I am unable to find how I can reference these constraints in the UserAnswer table.
@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
}
How can I achieve this?