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>
分享到:
相关推荐
@hibernate.joined-subclass-key(column="animal_id") public class Dog extends Animal { // ... } ``` #### 二、@hibernate Tag for Method Level 在方法级别上的@hibernate Tag通常用于定义集合或其他属性的...
本文将详细探讨Hibernate中处理继承关系的三种映射策略:subclass、joined-subclass以及union-subclass。 首先,让我们理解继承关系在面向对象编程中的重要性。继承允许我们创建一个类(子类)作为另一个类(父类)...
在XML映射文件中,可以使用`<subclass>`或`<joined-subclass>`元素来定义子类,而在注解方式下,可以使用`@Inheritance`和`@DiscriminatorValue`等注解。 7. Collection Mapping(集合映射) 当一个对象需要关联多...
配置文件:只配置父类的映射文件,在其中加入joined-subclass将两个子类实体映射关系添加 2) 数据库表:一张表,包括公共字段、特有字段、区分字段 实体层设计:与第一种方法设计一样,设计三个实体类,分父类和...
在 Hibernate 中处理多对多关系时,通常采用一种称为“连接表”或“关联表”的方法来实现两个实体之间的多对多关联。这种设计方式较为常见且实用,但并非适用于所有场景。 ##### 关联表设计 假设我们有两个实体:`...
### Hibernate中文参考文档知识点概述 #### 一、Hibernate简介与概念 **Hibernate** 是一个用于 Java 环境下的开源 **对象/关系映射 ... - **5.1.16 连接的子类 (joined-subclass)**:每种子类型一张表继承模式。
- **连接的子类映射**(`joined-subclass`):实现多表继承,每个子类有自己的表,通过`<joined-subclass>`元素映射。 ### Hibernate 查询语言 (HQL) HQL使我们能够用面向对象的方式来编写查询语句,避免了与SQL的...
Hibernate支持单继承和多层继承的映射,通过`<subclass>`或`<joined-subclass>`标签将子类映射到数据库中的特定表,这在设计复杂的对象模型时非常有用。 **四、一对一关系映射** 在`hibernate_one2one_ufk_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 ...
- **连接的子类(joined-subclass)**:多表继承的一种形式。 - **map,set,list,bag**:集合类型的映射。 - **引用(import)**:引入其他映射文件或类的快捷方式。 - **Hibernate的类型** - **实体(Entities...
此外,还可以通过`subclass`、`joined-subclass`或`union-subclass`元素实现类的继承映射。 总结来说,Hibernate的基础配置主要包括导入相关库和DTD文件,以及创建映射文件来定义实体类与数据库表的对应关系。映射...
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 ...
id>`(复合主键)、`<joined-subclass>`(共享表的继承)、`<subclass>`(单表的继承)、`<union-subclass>`(联合表的继承)、`<inverse>`(双向关联的维护关系)、`<cascade>`(级联操作)、`<version>`(乐观锁...
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 ...
非实体类型的组成部分用`component`表示,继承关系的描述中,单表策略用`subclass`,多表策略用`joined-subclass`或`table-per-class`。双向关联关系的维护属性为`inverse`,级联操作属性为`cascade`,乐观锁通常...