日期:2014-05-20 浏览次数:20785 次
public class Student { private int id;//学号 private String name;//姓名 private Set<Course> courses;//课程集 }
public class Course { private int id;//课程号 private String name;课程名 private Set<Student> students;//学生集 }
public class Score { private int score;//分数 }
<hibernate-mapping> <class name="com.cn.Student" table="t_student" > <id name="id" type="java.lang.Integer"> <column name="ID" length="4" /> <generator class="native"/> </id> <property name="name" type="java.lang.String"> <column name="NAME" /> </property> <set name="courses" lazy="true" cascade="all" table="t_stu_cou_score"> <key column="SID"></key> <many-to-many class="com.cn.Course" column="CID" /> </set> </class> </hibernate-mapping>
<hibernate-mapping> <class name="com.cn.Course" table="t_course"> <id name="id" type="java.lang.Integer"> <column name="ID" length="4" /> <generator class="native"/> </id> <property name="name" type="java.lang.String"> <column name="NAME" /> </property> <set name="students" lazy="true" cascade="all" table="t_stu_cou_score"> <key column="CID"></key> <many-to-many class="com.cn.Student" column="SID" /> </set> </class> </hibernate-mapping>