I'm trying to map 3 entities: Question, Answer and QuestionDisplayRule. Question has many Answers and many QuestionDisplayRules each of which belong to one Question. QuestionDisplayRule has one Question, one Answer and one field with String value. The db table for QuestionDisplayRule looks like this:
create table question_display_rule(
question_id int,
answer_id int,
answer_value varchar(128)
);
Naturally, question_id and answer_id are the PK.
JPA mapping looks like this:
@Embeddable
public class QuestionDisplayRulePK implements Serializable {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="question_id", insertable = false, updatable = false)
private Question question;
@ManyToOne
@JoinColumn(name = "answer_id", insertable = false, updatable = false)
private Answer answer;
}
and
@Entity
@Table(name = "question_display_rule")
public class QuestionDisplayRule implements Serializable {
@EmbeddedId
private QuestionDisplayRulePK id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="question_id", insertable = false, updatable = false)
private Question question;
@ManyToOne
@JoinColumn(name = "answer_id", insertable = false, updatable = false)
private Answer answer;
@Column(name="answer_value")
private String answerValue;
}
The problem is that it loads QuestionDisplayRules just fine if I add records manually in the DB but won't save them. No errors, no nothing..
Test code:
QuestionDisplayRulePK qPK = new QuestionDisplayRulePK();
qPK.setQuestion(q);
qPK.setAnswer(a);
QuestionDisplayRule qr = new QuestionDisplayRule(qPK, "Yes");
qr.setAnswerValue("whateva..");
....
// DAO code looks like: getSession().saveOrUpdate(qr);
Any ideas? Thanks!