Q:

Update HashSet values

My aim is to update Hashset values. I have Mapped two tables with onetomany & manytoone relationship.
My Flow
I have Examination and ExamPaper tables. In Examination i have created Set examPapers = new HashSet() with onetomany.I ExamPaper i just created a relationship with manytoone. I have successfully stored a values in two tables,i had a error in Update Section.Please Check my following coding.
POJO Examination 
private String examName;
private Set<ExamPaper> examPapers = new HashSet<ExamPaper>();

@Column(name = "exam_name") 
@Field
public String getExamName() {
    return examName;
}
public void setExamName(String examName) {
    this.examName = examName;
}

@OneToMany(cascade={CascadeType.ALL},fetch=FetchType.EAGER)
@JoinColumn(name="examination_id")
public Set<ExamPaper> getExamPapers() {
    return examPapers;
}
public void setExamPapers(Set<ExamPaper> examPapers) {
    this.examPapers = examPapers;
}

POJO ExamPaper 
private String maxMark;
private Examination examination;

@Column(name = "maxmark") 
@Field
public String getMaxMark() {
    return maxMark;
}
public void setMaxMark(String maxMark) {
    this.maxMark = maxMark;
}

@ManyToOne(cascade={CascadeType.ALL},fetch=FetchType.EAGER)
@JoinColumn(name="examination_id")
public Examination getExamination() {
    return examination;
}
public void setExamination(Examination examination) {
    this.examination = examination;
}

My Controller
Set<ExamPaper> examPapers=new HashSet<ExamPaper>();
String[] maxMarks=request.getParameterValues("maxMarks");
for (int i=0;i<maxMarks.length;i++) {
   ExamPaper examPaper = new ExamPaper();
   examPaper.setMaxMark(maxMarks[i]);
   examPapers.add(examPaper);
}
examination.setExamPapers(examPapers);
examinationService.saveOrUpdateExamination(examination);

This Code Successfully saved into DB. I am trying to update(ie add maxMarks or Remove maxMarks ) . It doubles the ExamPaper table Values and removes the Examination Id from ExamPaper.I have Attached Save and Update picture of DB. 
NOTE : First Part Examination , Second Part ExamPaper of each Picture.
save - http://postimg.org/image/xzg8qu3dh/ 
Update-  http://postimg.org/image/t22o5q1ed/
How to update? 

A:

I think, you have an error in your mapping, try to use this :
POJO Examination
 private Set<ExamPaper> examPapers = new HashSet<ExamPaper>();

 @OneToMany(cascade={CascadeType.ALL},fetch=FetchType.EAGER,  mappedBy='examination')
 public Set<ExamPaper> getExamPapers() {
  return examPapers;
 }

POJO ExamPaper
 private Examination examination;

 @ManyToOne(cascade={CascadeType.ALL},fetch=FetchType.EAGER)
 @JoinColumn(name="examination_id")
 public Examination getExamination() {
    return examination;
 }

afterwards, if you still have the same problem, add this line in the for loop inside your controller :
 examPaper.setExamination(examination);
 examPapers.add(examPaper);

