I am trying to use hibernate annotation to write a model class for my database tables.
I have two tables, each of which has a primary user key and a 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;
Table of questions.
@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;
And I have another UserAnswer table that has userId and questionId as foreign keys from the two above tables.
But I cannot find how I can refer to these restrictions 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 }
Please help me achieve this? Thanks in advance.
java hibernate hibernate-mapping hibernate-annotations
vikiiii Mar 15 '13 at 7:14 2013-03-15 07:14
source share