读书人

7.报表继承

发布时间: 2012-10-06 17:34:01 作者: rapoo

7.表格继承

name

desc

default

name

((Optional) The name of the table. Defaults to the entity name.

"DTYPE"

discriminatorType

(Optional) The type of object/column to use as a class discriminator. Defaults to DiscriminatorType.STRING.

STRING

columnDefinition

(Optional) The SQL fragment that is used when generating the DDL for the discriminator column.

Defaults to the provider-generated SQL to create a column of the specified discriminator type.

""

length

(Optional) The column length for String-based discriminator types. Ignored for other discriminator types.

31

DiscriminatorValue

Is used to specify the value of the discriminator column for entities of the given type. The DiscriminatorValue annotation can only be specified on a concrete entity class. If the DiscriminatorValue annotation is not specified and a discriminator column is used, a provider-specific function will be used to generate a value representing the entity type. If the DiscriminatorType is STRING, the discriminator value default is the entity name.

The inheritance strategy and the discriminator column are only specified in the root of an entity class hierarchy or subhierarchy in which a different inheritance strategy is applied. The discriminator value, if not defaulted, should be specified for each entity class in the hierarchy.

name

desc

default

value

(Optional) The value that indicates that the row is an entity of the annotated entity type.

If the DiscriminatorValue annotation is not specified and a discriminator column is used, a provider-specific function will be used to generate a value representing the entity type. If the DiscriminatorType is STRING, the discriminator value default is the entity name.

STRING

?

    Single Table Inheritance strategy

The SINGLE TABLE strategy maps all entities in the hierarchy to the base entity' table.

    Create a Single Table Base Entity

* Create a Base Entity.

7.报表继承

* Double click Base Entity

* Select a Inheritance strategy: InheritanceType.SINGLE_TABLE

* Check inheritance checkbox.

7.报表继承

    Create Mapped Relation

7.报表继承

7.报表继承

    Generate SQL Script

Click toolbar 7.报表继承

Base / Derived1 / Derived2

?

create table Base (DTYPE varchar(31) not null, id bigint not null auto_increment, baseName varchar(255), derived1Name varchar(255), derived2Name varchar(255), primary key (id));

    Joined Table Inheritance strategy

A strategy in which fields that are specific to a subentity are mapped to a separate table than the fields that are common to the base entity, and a join is performed to instantiate the subentity.

    Create a JOINED Table Base Entity

* Create a Base Entity.

7.报表继承

* Double click Base Entity

* Select a Inheritance strategy: InheritanceType.JOINED_TABLE

* Check inheritance checkbox.

7.报表继承

    Create Mapped Relation

7.报表继承

7.报表继承

    Generate SQL Script

Click toolbar 7.报表继承

Base Entity

create table Base (id bigint not null auto_increment, baseName varchar(255), primary key (id));

?

Derived1 Entity

create table Derived1 (derived1Name varchar(255), id bigint not null, primary key (id));

?

Derived2 Entity

create table Derived2 (derived2Name varchar(255), id bigint not null, primary key (id));

?

alter table Derived1 add index FK3F2C91D47D53AC8F (id), add constraint FK3F2C91D47D53AC8F foreign key (id) references Base (id);

alter table Derived2 add index FK3F2C91D57D53AC8F (id), add constraint FK3F2C91D57D53AC8F foreign key (id) references Base (id);

    Table PER Class Inheritance strategy
      Create Table PER Class Base Entity

Like the JOINED TABLE strategy, the TABLE PER CLASS strategy uses a different table for each entity in the hierarchy. Unlike the JOINED strategy, however, each table includes all state for an instance of the corresponding entity. it does not need to join to base entity tables.

* Create a Base Entity.

* Double click Base Entity

* Select a Inheritance strategy: InheritanceType.TABLE_PER_CLASS

* Check inheritance checkbox.

7.报表继承

    Create Mapped Relation

7.报表继承

7.报表继承

    Generate SQL Script

Click toolbar 7.报表继承

Base Entity

create table Base (id bigint not null auto_increment, baseName varchar(255), primary key (id));

?

Derived1 Entity

create table Derived1 (id bigint not null, baseName varchar(255), derived1Name varchar(255), primary key (id));

?

Derived2 Entity

create table Derived2 (id bigint not null, baseName varchar(255), derived2Name varchar(255), primary key (id));

?

读书人网 >编程

热点推荐