0

In my Hibernate Application i have Timetable(parent) classtable(child) is their.

My first operation is insert into Timetable and using this timetable many classtable inserted. Like onetomany Relation.

But i'm facing the Problem : first Timetable inserted and classtable inserted and again timetable and classtable..........so on..

But my intention is only one Timetable and Many classtable.

Hear is my Code...in Timetable

@OneToMany(mappedBy = "timetable",cascade={CascadeType.ALL})
    private Set<ClassTableVO> classtable;

And ClassTable

@ManyToOne(cascade={CascadeType.ALL})
    @JoinColumn(name = "COURSE_TABLE_ID")
    private TimetableVO timetable;

And if we remove (cascade={CascadeType.ALL}) it give Exception like object references an unsaved transient instance Please help me..

Edit:

In my Hibernate i'm using JPA EntityManager class

userDAO.createEvent(timetableVO);//this loop only one time executed 
------
-----
for(---){
userDAO.createClassTable(classTable);
}

and above method have two line of code in both two methods..

entityManager.merge(classTable);//
entityManager.flush();
java
  • 473
  • 3
  • 9
  • 15

1 Answers1

0

When you do a TimeTableVO.addClassTable(ClassTableVO ct) remember to set ClassTableVO.timetable:

public void TimeTableVO.addClassTable(ClassTableVO ct){
  if(classtable.add(ct)){
    ct.setTimetable(this);
  }
}

so link are correctly setter and Hibernate know ho to correctly cascade object while saving

Luca Basso Ricci
  • 17,829
  • 2
  • 47
  • 69