Squad.hbm.xml:
<many-to-one name="college" class="College" fetch="select">
<column name="collegeID" not-null="true" />
</many-to-one>College.hbm.xml
<set name="Squads" inverse="true">
<key>
<column name="collegeId" not-null="true" />
</key>
<one-to-many class="com.xxx.Squad" />
</set>
xml文件大体就这么写,你再自己查一下资料查询的话你只要得到所有的班级对象,然后通过squadObj.getCollege就可以得到对应的院系信息!
<many-to-one name="college" class="College" fetch="select">
<column name="collegeID" not-null="true" />
</many-to-one>College.hbm.xml
<set name="Squads" inverse="true">
<key>
<column name="collegeId" not-null="true" />
</key>
<one-to-many class="com.xxx.Squad" />
</set>
xml文件大体就这么写,你再自己查一下资料查询的话你只要得到所有的班级对象,然后通过squadObj.getCollege就可以得到对应的院系信息!
name="college"
class="eduoffice.dataaccess.College"
column="collegeId"
insert="false"
update="false"
not-null="true"
/>
College.hbm.xml中没有写,这行不可以吗?
squadObj.getCollege()你应该在你的Squad.java文件中定义
private College college;public College getCollege(){
return college();
}public void setCollege(College college){
this.college = college;
}
name="college"
class="eduoffice.dataaccess.College"
column="collegeId"
insert="false"
update="false"
not-null="true"
/>这个地方再加上lazy="false"这个属性