Hibernate如何一个类映射两个表

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

 

这叫“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>  
相关文章
相关标签/搜索