Hibernate如何一个类映射两个表

一个User类有username,password属性,还有 otherInformation等其他属性,username和password映射到一个表,otherInformation等其他属性映射到另一 个表,使用User类时不会感觉到是两个表的的存在,如何配置User.mapping.xml文件进行配置??

 

这叫“Table per subclass”:

Xml代码  收藏代码

    <class name="Base" table="表1">  
        <id name="id" type="long" column="BASE_ID">  
            <generator class="native"/>  
        </id>  
        <property name="username" column="username"/>  
        <property name="password" column="password"/>  
        ...  
        <joined-subclass name="User" table="表2">  
            <key column="BASE_ID"/>  
            <property name="otherInformation" column="otherInformation"/>  
            ...  
        </joined-subclass>  
      
    </class>  

 

posted @ 2015-11-18 13:32  liyunyu1  阅读(1053)  评论(0编辑  收藏  举报