0
在我的Hibernate應用程序中,我有Timetable(parent)classtable(child)是他們的。父對象在插入子對象時插入兩次
我的第一個操作是插入時間表,並使用這個時間表插入許多classtable。像onetomany關係。
,但我面對的問題:第一時間表插入classtable插入並再次時間表和classtable ..........等等..
但我的本意只是一個時間表和許多classtable。
聽到的是我的代碼...在時間表
@OneToMany(mappedBy = "timetable",cascade={CascadeType.ALL})
private Set<ClassTableVO> classtable;
而且ClassTable
@ManyToOne(cascade={CascadeType.ALL})
@JoinColumn(name = "COURSE_TABLE_ID")
private TimetableVO timetable;
如果我們去掉(cascade={CascadeType.ALL})
它給像object references an unsaved transient instance
異常請幫助我..
Edit:
在我的休眠我使用JPA EntityManager類
userDAO.createEvent(timetableVO);//this loop only one time executed
------
-----
for(---){
userDAO.createClassTable(classTable);
}
和上面的方法有兩種線在這兩個兩種方法代碼..
entityManager.merge(classTable);//
entityManager.flush();
當你w螞蟻保存 – Angga
其實我使用JPA EntityManager類,所以我使用合併()方法.. – java
檢查[這裏](http://stackoverflow.com/questions/1069992/jpa-entitymanager-why-use-persist關於marge()和persist()的討論;也許你需要堅持()而不是合併 –