7.映射组成关系

public class Customer implements java.io.Serializable {
<span style="white-space:pre">	</span>private Integer id;
<span style="white-space:pre">	</span>private String name;
<span style="white-space:pre">	</span>private Address homeAddress;
<span style="white-space:pre">	</span>private Address comAddress;

配置文件配置如下

<component name="homeAddress" class="cn.itcast.compopent.Address">
         <!-- 该配置表示Address是Customer类的一部分 -->
         <property name="street" type="string">
           <column name="home_street"></column>
         </property>
         
         <property name="city" type="string">
           <column name="home_city"></column>
         </property>
         
         <property name="province" type="string">
           <column name="home_province"></column>
         </property>
         
         <property name="zipcode" type="string">
           <column name="home_zipcode"></column>
         </property>
      </component>
      
       <component name="comAddress" class="cn.itcast.compopent.Address">
         <property name="street" type="string">
           <column name="com_street"></column>
         </property>
         
         <property name="city" type="string">
           <column name="com_city"></column>
         </property>
         
         <property name="province" type="string">
           <column name="com_province"></column>
         </property>
         
         <property name="zipcode" type="string">
           <column name="com_zipcode"></column>
         </property>
      </component>

*    两个javabean对应一张表,组件映射表中字段一般有重复内容,比如说地址,有家庭地址和公司地址

Address ha=c.getHomeAddress();
*   如果homeAddress对应的四个表字段为空  则c.getHomeAddress()为null

public class Address {
	private String street;
	private String city;
	private String province;
	private String zipcode;
	//表示Address所属的整体类
	private Customer customer;
hbm配置文件

<component name="homeAddress" class="cn.itcast.compopent.Address">
         <!-- 该配置表示Address是Customer类的一部分 -->
         <parent name="customer"/>
         <property name="street" type="string">
           <column name="home_street"></column>
         </property>
         <property name="city" type="string">
           <column name="home_city"></column>
         </property>
         <property name="province" type="string">
           <column name="home_province"></column>
         </property>
         <property name="zipcode" type="string">
           <column name="home_zipcode"></column>
         </property>
      </component>
*   在Address类中加上所属类,配置文件加一个parent标签也可以

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值