如果一个类的属性由几个component组成,同时这个类对应的数据库的表是一个表,则可以在class_name.hbm.xml中通过component来标识;
例如:
public class Tuser implements Serializable{
private Integer id;
private Contect contace;
private Name name;
}
public class Contact implements Serializable{
private String address;
private String zipcode;
private String tel;
}
public class Name implements Serializable{
private String firstname;
private String lastname;
}
下面为类Tuser的hbm.xml
<hibernate-mapping>
<class name="Tuer" table="T_USER">
<id name="id" column="id" type="java.lang.Integer">
<generator class="native"></generator>
</id>
<component name="name" class="Name">
<property name="firstname" column="firstname" type="string"/>
<property name="lastname" column="firstname" type="string"/>
</component>
<component name="contact" class="Contact">
<property name="address" column="addresss" type="string"/>
<property name="zipcode" column="zipcode" type="string"/>
<property name="tel" column="tel" type="string"/>
</component>
</class>
</hibernate-mapping>
第一个写blog,难免会有错误,希望能坚持把自己写笔记的习惯转移到blog上面