package hibernate.po; import java.util.Set; public class Dept { private int id; private String name; private Set<Memb> membs; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Set<Memb> getMembs() { return membs; } public void setMembs(Set<Memb> membs) { this.membs = membs; } }
package hibernate.po; public class Memb { private int id; private String username; private String password; private Dept dept; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public Dept getDept() { return dept; } public void setDept(Dept dept) { this.dept = dept; } }
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="hibernate.po"> <class name="Dept" table="dept"> <id name="id" column="id"> <generator class="native" /> </id> <property name="name" length="50" /> <set name="membs"> <key column="dept_id" foreign-key="fk_memb_dept"></key> <one-to-many class="Memb" /> </set> </class> </hibernate-mapping>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="hibernate.po"> <class name="Memb" table="memb"> <id name="id" column="id"> <generator class="native" /> </id> <property name="username" column="username" length="50" /> <property name="password" column="password" length="50" /> <many-to-one name="dept" foreign-key="fk_memb_dept"> <column name="dept_id" /> </many-to-one> </class> </hibernate-mapping>
时间: 2024-10-04 07:02:42