Hibernate支持三种继承映射策略
1.subclass
2.joined-subclass元素映射子类:继承树的每层实例对应一张表,且基类的表中保存所有子类的公有列,因此如需创建子类实例,总是需要查询基类的表数据,其子类所在深度越深,查询涉及到的表就越多。
3.unioned-subclass
joined-subclass的例子:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1
http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->
<class
name="com.ibm.cdl.scst.domain.processdata.ProcessData"
table="PROCESSDATA"
dynamic-update="true"
dynamic-insert="true"
select-before-update="true">
<meta attribute="class-description" inherit="false">
@hibernate.class
table="PROCESSDATA"
dynamic-update="true"
dynamic-insert="true"
select-before-update="true"
</meta>
<meta attribute="implement-equals" inherit="false">true</meta>
<meta attribute="implements" inherit="false">com.ibm.cdl.common.Identifiable</meta>
<meta attribute="implements" inherit="false">com.ibm.cdl.common.Versionable</meta>
<id
name="id"
type="int"
column="ID"
unsaved-value="0"
>
<meta attribute="field-description">
@hibernate.id
generator-class="identity"
type="int"
column="ID"
unsaved-value="0"
</meta>
<generator class="identity" />
</id>
<!--
<version
name="version"
type="int"
column="VERSION"
/>
-->
<property
name="processStarter"
type="java.lang.String"
column="PROCESS_STARTER"
not-null="true"
length="100"
>
<meta attribute="field-description">
@hibernate.property
column="PROCESS_STARTER"
length="100"
not-null="true"
</meta>
</property>
<property
name="processInstanceId"
type="long"
column="PROCESS_INSTANCE_ID"
length="100"
>
<meta attribute="field-description">
@hibernate.property
column="PROCESS_INSTANCE_ID"
length="100"
</meta>
</property>
<property
name="active"
type="boolean"
column="IS_ACTIVE"
not-null="true"
length="10"
>
<meta attribute="field-description">
@hibernate.property
column="IS_ACTIVE"
length="10"
not-null="true"
</meta>
</property>
<property
name="createCep"
type="boolean"
column="CREATE_CEP"
length="1"
>
<meta attribute="field-description">
@hibernate.property
column="CREATE_CEP"
length="1"
</meta>
</property>
<property
name="startTime"
type="java.util.Date"
column="START_TIME"
length="26"
>
<meta attribute="field-description">
@hibernate.property
column="CREATE_TIME"
length="26"
</meta>
</property>
<property
name="finishTime"
type="java.util.Date"
column="FINISH_TIME"
length="26"
>
<meta attribute="field-description">
@hibernate.property
column="FINISH_TIME"
length="26"
</meta>
</property>
<!-- Associations -->
<!-- bi-directional many-to-one association to Cep -->
<many-to-one
name="cep"
class="com.ibm.cdl.scst.domain.Cep"
not-null="true"
fetch="join"
lazy="false"
cascade="none"
>
<meta attribute="field-description">
@hibernate.many-to-one
not-null="true"
@hibernate.column name="CEP_ID"
</meta>
<column name="CEP_ID" />
</many-to-one>
<!-- bi-directional many-to-one association to Maintenance -->
<many-to-one
name="maintenance"
class="com.ibm.cdl.scst.domain.Maintenance"
not-null="true"
fetch="join"
lazy="false"
>
<meta attribute="field-description">
@hibernate.many-to-one
not-null="true"
@hibernate.column name="MAINTENANCE_ID"
</meta>
<column name="MAINTENANCE_ID" />
</many-to-one>
<joined-subclass
name="com.ibm.cdl.scst.domain.processdata.ConfidentialChangeProcessData"
table="PROCESSDATA_CONFIDENTIAL_CHANGE"
dynamic-update="true"
dynamic-insert="true">
<key column="ID" />
<property
name="changeToConfidential"
type="boolean"
column="CHANGE_TO_CONFIDENTIAL"
not-null="true"
length="1"
>
<meta attribute="field-description">
@hibernate.property
column="CHANGE_TO_CONFIDENTIAL"
length="1"
not-null="true"
</meta>
</property>
<property
name="checkList"
type="java.lang.String"
column="CHECK_LIST"
length="200"
>
<meta attribute="field-description">
@hibernate.property
column="CHECK_LIST"
length="200"
</meta>
</property>
<property
name="cbnId"
type="int"
column="CBN_ID"
length="10"
>
<meta attribute="field-description">
@hibernate.property
column="CBN_ID"
length="10"
</meta>
</property>
</joined-subclass>
<joined-subclass
name="com.ibm.cdl.scst.domain.processdata.SystemRebuildProcessData"
table="PROCESSDATA_SYSTEM_REBUILD"
dynamic-update="true"
dynamic-insert="true">
<key column="ID" />
<property
name="installType"
type="string"
column="INSTALL_TYPE"
not-null="true"
length="50"
>
<meta attribute="field-description">
@hibernate.property
column="INSTALL_TYPE"
length="50"
not-null="true"
</meta>
</property>
<property
name="changeTicketNo"
type="java.lang.String"
column="CHANGE_TICKET_NO"
length="100"
>
<meta attribute="field-description">
@hibernate.property
column="CHANGE_TICKET_NO"
length="100"
</meta>
</property>
<property
name="justification"
type="java.lang.String"
column="JUSTIFICATION"
length="1000"
>
<meta attribute="field-description">
@hibernate.property
column="JUSTIFICATION"
length="1000"
</meta>
</property>
<property
name="justificationFilePath"
type="java.lang.String"
column="JUSTIFICATION_FILE_PATH"
length="200"
>
<meta attribute="field-description">
@hibernate.property
column="JUSTIFICATION_FILE_PATH"
length="200"
</meta>
</property>
<property
name="justificationFileName"
type="java.lang.String"
column="JUSTIFICATION_FILE_NAME"
length="200"
>
<meta attribute="field-description">
@hibernate.property
column="JUSTIFICATION_FILE_NAME"
length="200"
</meta>
</property>
<property
name="needChangeItAdmin"
type="boolean"
column="NEED_CHANGE_IT_ADMIN"
length="1"
>
<meta attribute="field-description">
@hibernate.property
column="NEED_CHANGE_IT_ADMIN"
length="1"
</meta>
</property>
<property
name="confidentialSettingProcessInstanceId"
type="long"
column="CONFIDENTIALSETTING_ID"
length="10"
>
<meta attribute="field-description">
@hibernate.property
column="CONFIDENTIALSETTING_ID"
length="10"
</meta>
</property>
<property
name="confidentialSettingStartTime"
type="java.util.Date"
column="CONFIDENTIALSETTING_STARTTIME"
length="10"
>
<meta attribute="field-description">
@hibernate.property
column="CONFIDENTIALSETTING_STARTTIME"
length="1"
</meta>
</property>
<property
name="confidentialSettingFinishTime"
type="java.util.Date"
column="CONFIDENTIALSETTING_FINISHTIME"
length="10"
>
<meta attribute="field-description">
@hibernate.property
column="CONFIDENTIALSETTING_FINISHTIME"
length="10"
</meta>
</property>
</joined-subclass>
<joined-subclass
name="com.ibm.cdl.scst.domain.processdata.SystemInitializationProcessData"
table="PROCESSDATA_SYSTEM_INITIALIZATION"
dynamic-update="true"
dynamic-insert="true">
<key column="ID" />
<property
name="justification"
type="java.lang.String"
column="JUSTIFICATION"
length="1000"
>
<meta attribute="field-description">
@hibernate.property
column="JUSTIFICATION"
length="1000"
</meta>
</property>
<property
name="confidentialSettingProcessInstanceId"
type="long"
column="CONFIDENTIALSETTING_ID"
length="10"
>
<meta attribute="field-description">
@hibernate.property
column="CONFIDENTIALSETTING_ID"
length="1"
</meta>
</property>
</joined-subclass>
<joined-subclass
name="com.ibm.cdl.scst.domain.processdata.SystemRemovalProcessData"
table="PROCESSDATA_SERVER_REMOVAL"
dynamic-update="true"
dynamic-insert="true">
<key column="ID" />
<property
name="evidence"
type="string"
column="EVIDENCE"
length="1000"
>
<meta attribute="field-description">
@hibernate.property
column="EVIDENCE"
length="1000"
</meta>
</property>
<property
name="evidenceFilePath"
type="string"
column="EVIDENCE_FILE_PATH"
not-null="false"
length="200"
>
<meta attribute="field-description">
@hibernate.property
column="EVIDENCE_FILE_PATH"
not-null="false"
length="200"
</meta>
</property>
<property
name="evidenceFileName"
type="string"
column="EVIDENCE_FILE_NAME"
not-null="false"
length="200"
>
<meta attribute="field-description">
@hibernate.property
column="EVIDENCE_FILE_NAME"
not-null="false"
length="200"
</meta>
</property>
</joined-subclass>
</class>
</hibernate-mapping>
分享到:
相关推荐
配置文件:只配置父类的映射文件,在其中加入joined-subclass将两个子类实体映射关系添加 2) 数据库表:一张表,包括公共字段、特有字段、区分字段 实体层设计:与第一种方法设计一样,设计三个实体类,分父类和...
5.1.16. 连接的子类(joined-subclass) 5.1.17. 联合子类(union-subclass) 5.1.18. 连接(join) 5.1.19. 键(key) 5.1.20. 字段和规则元素(column and formula elements) 5.1.21. 引用(import) 5.1.22. any ...
5.1.16. 连接的子类(joined-subclass) 5.1.17. 联合子类(union-subclass) 5.1.18. 连接(join) 5.1.19. 键(key) 5.1.20. 字段和规则元素(column and formula elements) 5.1.21. 引用(import) 5.1.22. any ...
5.1.16. 连接的子类(joined-subclass) 5.1.17. 联合子类(union-subclass) 5.1.18. 连接(join) 5.1.19. 键(key) 5.1.20. 字段和规则元素(column and formula elements) 5.1.21. 引用(import) 5.1.22. any ...
5.1.16. 连接的子类(joined-subclass) 5.1.17. 联合子类(union-subclass) 5.1.18. 连接(join) 5.1.19. 键(key) 5.1.20. 字段和规则元素(column and formula elements) 5.1.21. 引用(import) 5.1.22. any 5.2. ...
5.1.16. 连接的子类(joined-subclass) 5.1.17. 联合子类(union-subclass) 5.1.18. 连接(join) 5.1.19. 键(key) 5.1.20. 字段和规则元素(column and formula elements) 5.1.21. 引用(import) 5.1.22. any ...
5.1.16. 连接的子类(joined-subclass) 5.1.17. 联合子类(union-subclass) 5.1.18. 连接(join) 5.1.19. 键(key) 5.1.20. 字段和规则元素(column and formula elements) 5.1.21. 引用(import) 5.1.22. any ...
5.1.15. 连接的子类(joined-subclass) 5.1.16. 联合子类(union-subclass) 5.1.17. 连接(join) 5.1.18. 键(key) 5.1.19. 字段和规则元素(column and formula elements) 5.1.20. 引用(import) 5.1.21. any 5.2. ...
连接的子类(joined-subclass) 6.1.16. 联合子类(union-subclass) 6.1.17. 连接(join) 6.1.18. 键(key) 6.1.19. 字段和规则元素(column and formula elements) 6.1.20. 引用(import) 6.1.21. any 6.2. ...
5.1.16. joined-subclass 5.1.17. union-subclass 5.1.18. join 5.1.19. key 5.1.20. column and formula elements 5.1.21. import 5.1.22. any 5.2. Hibernate Types 5.2.1. Entities and values 5.2.2. Basic ...
连接的子类(joined-subclass) 6.1.16. 联合子类(union-subclass) 6.1.17. 连接(join) 6.1.18. 键(key) 6.1.19. 字段和规则元素(column and formula elements) 6.1.20. 引用(import) 6.1.21. any 6.2. ...
5.1.15. 连接的子类(joined-subclass) 5.1.16. 联合子类(union-subclass) 5.1.17. 连接(join) 5.1.18. 键(key) 5.1.19. 字段和规则元素(column and formula elements) 5.1.20. 引用(import) 5.1.21. any 5.2. ...
连接的子类(joined-subclass) 6.1.16. 联合子类(union-subclass) 6.1.17. 连接(join) 6.1.18. 键(key) 6.1.19. 字段和规则元素(column and formula elements) 6.1.20. 引用(import) 6.1.21. any 6.2. ...
连接的子类(joined-subclass) 5.1.17. 联合子类(union-subclass) 5.1.18. 连接(join) 5.1.19. 键(key) 5.1.20. 字段和规则元素(column and formula elements) 5.1.21. 引用(import) 5.1.22. any 5.2. ...
连接的子类(joined-subclass) 5.1.15. map, set, list, bag 5.1.16. 引用(import) 5.2. Hibernate 的类型 5.2.1. 实体(Entities)和值(values) 5.2.2. 基本值类型 5.2.3. 持久化枚举...
连接的子类(joined-subclass) 5.1.15. 联合子类(union-subclass) 5.1.16. 连接 5.1.17. map, set, list, bag 5.1.18. 引用(import) 5.2. NHibernate 的类型 5.2.1. 实体(Entities)和值(values) ...
• Joined Subclass Strategy: the <joined-subclass> element in Hibernate 连接的子类策略 @Inheritance 注解来定义所选的之类策略。 每个类一张表 @Entity @Inheritance(strategy = InheritanceType.TABLE_PER...
连接的子类(joined-subclass) 6.1.16. 联合子类(union-subclass) 6.1.17. 连接(join) 6.1.18. 键(key) 6.1.19. 字段和规则元素(column and formula elements) 6.1.20. 引用(import) 6.1.21. any 6.2. ...
5.1.16. 连接的子类(joined-subclass) 5.1.17. 联合子类(union-subclass) 5.1.18. 连接(join) 5.1.19. 键(key) 5.1.20. 字段和规则元素(column and formula elements) 5.1.21. 引用(import) 5.1.22. any 5.2. ...
连接的子类(joined-subclass) 5.1.15. map, set, list, bag 5.1.16. 引用(import) 5.2. Hibernate 的类型 5.2.1. 实体(Entities)和值(values) 5.2.2. 基本值类型 5.2.3. 持久化枚举...