*.hbm.xml这里面的property中的类型要与beans中定义的一致,比如id,要定义了integer类型,就必须统一是,否则不能入库,还有记得要在hibernate.cfg.xml中配置需要生成对应表的bean的目录:
<!-- 映射资源 -->
<mapping resource="com/stuman/domain/Admin.hbm.xml"/>
<mapping resource="com/stuman/domain/Classes.hbm.xml"/>
<mapping resource="com/stuman/domain/Course.hbm.xml"/>
<mapping resource="com/stuman/domain/Enrol.hbm.xml"/>
<mapping resource="com/stuman/domain/Student.hbm.xml"/>
<mapping resource="com/stuman/domain/Teacher.hbm.xml"/>
<id name="id" type="integer">
<column name="id"></column>
<generator class="increment"></generator>
</id>
还有多对一,一对多的配置:
<!-- 多对一映射 -->
<many-to-one name="teacher" class="com.stuman.domain.Teacher" fetch="select">
<column name="tea_id"></column>
</many-to-one>
<!-- 设置关联关系 -->
<set name="classeses" inverse="true">//inverse表示发生变化是,以classeses为准
<key>
<column name="tea_id"></column>
</key>
<one-to-many class="com.stuman.domain.Classes"/>
</set>