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就可以得到对应的院系信息!

解决方案 »

  1.   

    我只在Squad.hbm.xml文件中写:<many-to-one
        name="college" 
        class="eduoffice.dataaccess.College"
        column="collegeId"
        insert="false"
        update="false"
        not-null="true"
    />
    College.hbm.xml中没有写,这行不可以吗?
      

  2.   

    配置文件写好后,怎么样在session.createQuery()方法中写HQL语句?
      

  3.   

    from Squad a 就是了,然后对应每一个squadObj得到相应的college 
    squadObj.getCollege()你应该在你的Squad.java文件中定义
    private College college;public College getCollege(){
        return college();
    }public void setCollege(College college){
        this.college = college;    
    }
      

  4.   

    不要忘记在<many-to-one
        name="college" 
        class="eduoffice.dataaccess.College"
        column="collegeId"
        insert="false"
        update="false"
        not-null="true"
    />这个地方再加上lazy="false"这个属性