日期:2014-05-17 浏览次数:20875 次
import java.util.Set;
public class One {
private int stuid;
private String stuname;
private Set<Many> manys;
public Set<Many> getManys() {
return manys;
}
public void setManys(Set<Many> manys) {
this.manys = manys;
}
public int getStuid() {
return stuid;
}
public void setStuid(int stuid) {
this.stuid = stuid;
}
public String getStuname() {
return stuname;
}
public void setStuname(String stuname) {
this.stuname = stuname;
}
}
public class Many {
private int stuid;
private int score;
private One oner;
public One getOner() {
return oner;
}
public void setOner(One oner) {
this.oner = oner;
}
public int getStuid() {
return stuid;
}
public void setStuid(int stuid) {
this.stuid = stuid;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}
<?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 package="com.pojo">
<class name="One" table="one" lazy="false"> <!-- 类对应一个表 -->
<id name="stuid" column="stuid">
<generator class="assigned" /> <!-- 主键的生成策略 -->
</id>
<property name="stuname"/>
<set name="manys" lazy="false" cascade="all">
<key column="stuid"></key>
<one-to-many class="Many" />
</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 package="com.pojo">
<class name="Many" table="many" lazy="false"> <!-- 类对应一个表 -->
<id name="stuid" column="stuid">
<generator class="assigned" /> <!-- 主键的生成策略 -->
</id>
<property name="score"/>
<many-to-one name="oner" class="One" cascade="all"
lazy="false">
<column name="stuid"></column>
</many-to-one>
</class>
</hibernate-mapping>