public class Classes implements Serializable { private Long cid; private String name; private String description; private Set<Student> students; public Long getCid() { return cid; } public void setCid(Long cid) { this.cid = cid; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Set<Student> getStudents() { return students; } public void setStudents(Set<Student> students) { this.students = students; } }
public class Student implements Serializable{ private Long sid; private String name; private String description; private Classes classes; public Long getSid() { return sid; } public void setSid(Long sid) { this.sid = sid; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Classes getClasses() { return classes; } public void setClasses(Classes classes) { this.classes = classes; } }
<?xml version="1.0" encoding="utf-8"?> <!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.sn.domain.Classes"> <id name="cid" type="java.lang.Long" length="5"> <generator class="increment"></generator> </id> <property name="name" length="20"></property> <property name="description" length="50"></property> <set name="students" cascade="all" inverse="false"> <key> <column name="cid"></column> </key> <one-to-many class="com.sn.domain.Student"/> </set> </class> </hibernate-mapping>
<?xml version="1.0" encoding="utf-8"?> <!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.sn.domain.Student"> <id name="sid" type="java.lang.Long" length="5"> <generator class="increment"></generator> </id> <property name="name" length="20"></property> <property name="description" length="50"></property> <many-to-one name="classes" column="cid" class="com.sn.domain.Classes"></many-to-one> </class> </hibernate-mapping>
时间: 2024-10-14 21:57:44