Hi,
I'm struggling to succcessfully achieve a one-to-many mapping.
The "one" side is a class called GradingForm, which contains a list of Answer objects. I'm trying to map this using a join table.
The relevant portion of my GradingForm class is:
Code:
public class GradingForm implements Grading, Serializable,
Comparable<GradingForm> {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
@Column(name = "GradingID")
private int gradingID;
@OneToMany(cascade = CascadeType.ALL)
@JoinTable(name = "gradinganswers", joinColumns = @JoinColumn(name = "gradingID", unique = true), inverseJoinColumns = @JoinColumn(name = "answerId"))
private List<Answer> answers;
The Answer class is
Code:
public class Answer implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "AnswerID")
private int answerId;
@Column(name = "GradingID")
private boolean gradingID = false;
My questions are:
1) The columns referenced within the JoinTable statement are the Java instance variables - this should be the join table columns instead, right?
2) Is there anything I'm missing? My code does persist the items (when I change the stuff in Question 1), but does not seem to add the id of the GradingForm into the correct column of the join table.
Any & all help appreciated!