I have a simple model with a Question
and Choice
object.
- ONE Question has MANY CHOICE(S).
- MANY Choice has ONE Question
There are two ways to implement that with Hibernate
Implementation One: The owner side is Choice
Question.java
@OneToMany (mappedBy="question")
private Set choices = new HashSet();
Choice.java
@ManyToOne
@JoinColumn (name="QUESTION_ID")
private Question question;
Implementation Two: The owner side is Question
Question.java
@OneToMany
@JoinColumn (name = "QUESTION_ID")
private Set choices = new HashSet();
Choice.java
@ManyToOne
@JoinColumn (name="QUESTION_ID", updatable = false, insertable = false)
private Question question;
What is the difference between the two implementation?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…