Hibernate Many-to-Many, duplicates same record

落花浮王杯 提交于 2019-12-02 07:05:19

You first need to get Student from database and then add courses to that object, and then save the fetched object.

This way, You are creating a new Student object, this new student object have a null in the "ID" instance variable. It seems to me that Hibernate must be mapping this instance variable to the primary key for look up, if id is found, record is updated else new record is inserted..

and yes, if u need to add the course for existing student, U might want to first get set from fetched student object, then add a course in that set, then save......else the new hash set will only contain the new course, and previous record will be overwritten.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!