`
j2ee_zhongqi
  • 浏览: 204417 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

Hibernate 中的joined-subclass

阅读更多
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>
分享到:
评论

相关推荐

    Hibernate3.1_学习源码

    配置文件:只配置父类的映射文件,在其中加入joined-subclass将两个子类实体映射关系添加 2) 数据库表:一张表,包括公共字段、特有字段、区分字段 实体层设计:与第一种方法设计一样,设计三个实体类,分父类和...

    hibernate3.2中文文档(chm格式)

    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 ...

    Hibernate+中文文档

    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 ...

    Hibernate中文详细学习文档

    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 ...

    Hibernate 中文 html 帮助文档

    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. ...

    HibernateAPI中文版.chm

    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 ...

    Hibernate_3.2.0_符合Java习惯的关系数据库持久化

    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 ...

    最全Hibernate 参考文档

    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. ...

    Hibernate3的帮助文档

    连接的子类(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. ...

    Hibernate Reference Documentation3.1

    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 ...

    hibernate3.04中文文档.chm

    连接的子类(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. ...

    Hibernate3+中文参考文档

    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. ...

    Hibernate教程

    连接的子类(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. ...

    hibernate 体系结构与配置 参考文档(html)

    连接的子类(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 教程

    连接的子类(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. 持久化枚举...

    NHibernate中文帮助手册API

    连接的子类(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) ...

    Hibernate注释大全收藏

    • Joined Subclass Strategy: the &lt;joined-subclass&gt; element in Hibernate 连接的子类策略 @Inheritance 注解来定义所选的之类策略。 每个类一张表 @Entity @Inheritance(strategy = InheritanceType.TABLE_PER...

    hibernate 框架详解

    连接的子类(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. ...

    Hibernate参考文档

    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

    连接的子类(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. 持久化枚举...

Global site tag (gtag.js) - Google Analytics