開發日誌:hibernate映射,一個類映射多個表

在解決項目中一個表字段映射多個實體屬性的時候發現這個提問,覺得很有意思

一個User類有username,password屬性,還有otherInformation等其他屬性,username和password映射到一個表,otherInformation等其他屬性映射到另一個表,使用User類時不會感覺到是兩個表的的存在,如何配置User.mapping.xml文件進行配置?
這叫“Table per subclass”:
<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>  

原:http://www.iteye.com/problems/4615
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章