public class Wife {
private Long id;
private String name;
private Husband husband;
public class Husband {
private Long id;
private String name;
private Wife wife;

外键保存在husband的表中

<?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>
<class name="hiber.Wife" table="wife">
<id name="id" type="java.lang.Long">
<column name="ID" scale="0" />
<!-- The generator-class attribute of @hibernate.id is deprecated, use the @hibernate.generator tag instead -->
<generator class="increment">
</generator>
</id>

<property name="name" type="java.lang.String" >
<column name="name" length="255"></column>
</property>
<one-to-one name="husband" property-ref="wife"></one-to-one>
</class>

<class name="hiber.Husband" table="Husband">
<id name="id" type="java.lang.Long">
<column name="ID" scale="0" />
<!-- The generator-class attribute of @hibernate.id is deprecated, use the @hibernate.generator tag instead -->
<generator class="increment">
</generator>
</id>

<property name="name" type="java.lang.String" >
<column name="name" length="255"></column>
</property>
<many-to-one name="wife" class="hiber.Wife" lazy="false" unique="true" not-null="true" cascade="all" >
<column name="wife_id" scale="0" />
</many-to-one>
</class></hibernate-mapping>


测试:
Wife wife = new Wife();
Husband husband = new Husband();
wife.setName("wife777");
husband.setName("husband777");
husband.setWife(wife);
// wife.setHusband(husband);
sph.save(wife);
sph.save(husband);
//进行访问
Wife wife1 = sph.get(4l);
System.out.println(wife1.getName()+":"+wife1.getHusband().getName());

Husband husband1 = sph.getHusband(3l);
System.out.println(husband1.getName()+":"+husband1.getWife().getName());