package org.hibernate.demo.entity;
import java.io.Serializable;
public class Husband implements Serializable
{
private Integer id;
private String name;
private Wife wife;
public Integer getId()
{
return id;
}
public void setId(Integer id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public Wife getWife()
{
return wife;
}
public void setWife(Wife wife)
{
this.wife = wife;
}
public Husband()
{
// TODO Auto-generated constructor stub
}
}
-----------------------------
package org.hibernate.demo.entity;
import java.io.Serializable;
import javax.persistence.Column;
public class Wife implements Serializable
{
private String name;
private Integer wifeAge;
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public Integer getWifeAge()
{
return wifeAge;
}
public void setWifeAge(Integer wifeAge)
{
this.wifeAge = wifeAge;
}
public Wife()
{
// TODO Auto-generated constructor stub
}
}
-----------------------
<?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="org.hibernate.demo.entity">
<class name="Husband">
<id name="id">
<generator class="identity" />
</id>
<property name="name" />
<!-- 组建映射 -->
<component name="wife" class="Wife">
<property name="name" column="wifeName"></property>
<property name="wifeAge"></property>
</component>
</class>
</hibernate-mapping>