开发日志:hibernate映射,一个类映射多个表

来源:互联网 发布:加工中心软件编程 编辑:程序博客网 时间:2024/05/15 08:28
在解决项目中一个表字段映射多个实体属性的时候发现这个提问,觉得很有意思

一个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
原创粉丝点击