<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.tudou.hibernates.e2.Student" table="tb_student">
<id name="stu_id" type="java.lang.Integer" column="stu_id">
<generator class="native">
</generator>
</id>
<property name="stuName" />
<set name="course" table="stu_course" cascade="save-update">
<key>
<column name="stu_id"></column>
</key>
<many-to-many class="com.tudou.hibernates.e2.Course"
column="cid" />
</set>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.tudou.hibernates.e2.Course" table="tb_course">
<id name="cid" type="java.lang.Integer" column="cid">
<generator class="native" />
</id>
<property name="courseName"></property>
</class>
</hibernate-mapping>
package com.tudou.hibernates.e2;
import java.util.HashSet;
import java.util.Set;
public class Course {
private int cid;
private String courseName;
public int getCid() {
return cid;
}
public void setCid(int cid) {
this.cid = cid;
}
public String getCourseName() {
return courseName;
}
public void setCourseName(String courseName) {
this.courseName = courseName;
}
}
package com.tudou.hibernates.e2;
import java.util.HashSet;
import java.util.Set;
public class Student {
private int stu_id;
private String stuName;
private Set<Course> course = new HashSet<Course>();
public int getStu_id() {
return stu_id;
}
public void setStu_id(int stuId) {
stu_id = stuId;
}
public String getStuName() {
return stuName;
}
public void setStuName(String stuName) {
this.stuName = stuName;
}
public Set<Course> getCourse() {
return course;
}
public void setCourse(Set<Course> course) {
this.course = course;
}
}