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>

猜你喜欢

转载自j2ee-zhongqi.iteye.com/blog/1046931