【发布时间】:2018-04-07 03:00:36
【问题描述】:
背景:我希望用户参加员工筛选测试,其中每个问题都与另一个问题“配对”,但问题的措辞不同。
用户类中下面的 HashMap 仅在以下情况下才有效:
Map<Question, Answer> answers = new HashMap<>();
但是,对于两个类似的问题,我的程序会有两个不同的答案。关于我应该如何设置课程的任何建议?尝试持久化 HashMap 的 HashMap 有意义吗?我应该为 MatchingAnswers 开设单独的课程吗?
谢谢
@Entity
public class User {
@Id
@GeneratedValue
int id;
@OneToMany(mappedBy = "user")
@MapKeyJoinColumn(name="QUESTION_ID")
Map<Map<Question, QuestionMatch>,Answer> answers = new HashMap<>();
}
.
@Entity
public class Question {
@Id
@GeneratedValue
private int id;
@NotNull
@Size(min = 3, message = "Please add a question")
private String question1;
public Integer desiredAnswer1;
private Boolean matchingOpposite;
@OneToOne //not sure if this is necessary
QuestionMatch matchingQuestion;
.
@Entity
public class Answer {
@Id
@GeneratedValue
private long id;
private int answer;
private int matchingAnswer;
@ManyToOne
private User user;
@ManyToOne
@JoinColumn(name="QUESTION_ID")
Question question;
.
@Entity
public class QuestionMatch {
@Id
@GeneratedValue
private int id;
@NotNull
@Size(min=3, message = "Please add a question")
private String questionMatch;
public int desiredAnswerForQuestionMatch;
【问题讨论】:
标签: java database hibernate hashmap persistence