Person.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.soft.gread1">
<class name="People" table="t_people">
<id name="id" >
<generator class="foreign">
<param name="property">idcard</param>
</generator>
</id>
<property name="name"/>
<!-- 在外键关联时要用many-to-one 此时使用了级联的方式 当然也可以不使用级联的方式 这就需要先保存 关联的对象了 -->
<many-to-one name="idcard" unique="true" cascade="all"></many-to-one>
</class>
</hibernate-mapping>
-----------------------------------------------------------------------------------------
IdCard.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.soft.gread1">
<class name="IdCard" table="t_idcard">
<id name="id" >
<generator class="native"/>
</id>
<property name="cardNo" />
</class>
</hibernate-mapping>