Lesson - 60 : Hibernate - Many To Many Adding child Operation using XML and Annotation based Config

Опубликовано: 08 Октябрь 2024
на канале: Sada Learning Hub
66
1

Hibernate – Assotations/Relationship : Add Operation in Many To Many :
The following are the four steps:
1. Load student from database. - Student stu=(Student)session.get(Student.class, 1001);
2. Read courses of the student into collection. - Set s = stu.getCourse();
3. Create a new course - Course c3 = new Course();c3.setCourseId(903);c3.setCourseName("cpp");c3.setDuration(60);
4. Add the new course to collection with in a transaction. - s.add(c3);

<set name="students" cascade="all" table="STUDENTS_COURSES">
<key column = "CID" />
<many-to-many class="com.sada.Model.Student" column="STUID"></many-to-many>
</set>


<set name="course" cascade="all" table="STUDENTS_COURSES">
<key column = "STUID" />
<many-to-many class="com.sada.Model.Course" column="CID"></many-to-many>
</set>

Hibernate Examples Project Github Link : https://github.com/SadaLearningHub1/H...