TableGenerator (Java EE 5)

Java EE API


javax.persistence Annotation Type TableGenerator


@Target(value={TYPE,METHOD,FIELD})
@Retention(value=RUNTIME)
public @interface TableGenerator

Implements: Annotation
@Target(value={TYPE, METHOD, FIELD})
@Retention(value=RUNTIME)

此注释定义为 GeneratedValue 注释指定生成器元素时可以通过名称引用的主键生成器。可以对实体类或主键字段或属性指定表格生成器。生成器名称的范围对于持久性单元是全局的(跨所有生成器类型)。
示例 1:
    
    @Entity public class Employee {
        ...
        @TableGenerator(
            name="empGen", 
            table="ID_GEN", 
            pkColumnName="GEN_KEY", 
            valueColumnName="GEN_VALUE", 
            pkColumnValue="EMP_ID", 
            allocationSize=1)
        @Id
        @GeneratedValue(strategy=TABLE, generator="empGen")
        public int id;
        ...
    }
    
示例 2:
    
    @Entity public class Address {
        ...
        @TableGenerator(
            name="addressGen", 
            table="ID_GEN", 
            pkColumnName="GEN_KEY", 
            valueColumnName="GEN_VALUE", 
            pkColumnValue="ADDR_ID")
        @Id
        @GeneratedValue(strategy=TABLE, generator="addressGen")
        public int id;
        ...
    }
 
英文文档:

This annotation defines a primary key generator that may be referenced by name when a generator element is specified for the GeneratedValue annotation. A table generator may be specified on the entity class or on the primary key field or property. The scope of the generator name is global to the persistence unit (across all generator types).

    Example 1:
    
    @Entity public class Employee {
        ...
        @TableGenerator(
            name="empGen", 
            table="ID_GEN", 
            pkColumnName="GEN_KEY", 
            valueColumnName="GEN_VALUE", 
            pkColumnValue="EMP_ID", 
            allocationSize=1)
        @Id
        @GeneratedValue(strategy=TABLE, generator="empGen")
        public int id;
        ...
    }
    
    Example 2:
    
    @Entity public class Address {
        ...
        @TableGenerator(
            name="addressGen", 
            table="ID_GEN", 
            pkColumnName="GEN_KEY", 
            valueColumnName="GEN_VALUE", 
            pkColumnValue="ADDR_ID")
        @Id
        @GeneratedValue(strategy=TABLE, generator="addressGen")
        public int id;
        ...
    }
 

Since:
Java Persistence 1.0

Required Element Summary
 String
 
Optional Element Summary
 int
 String
 int
 String
 String
 String
 String
 UniqueConstraint[]
 String
 

Element Detail

abstract public String name()
(必需)可以被将用作 ID 值生成器的一个或多个类引用的唯一生成器名称。
英文文档:

name

public abstract String name
(Required) A unique generator name that can be referenced by one or more classes to be the generator for id values.

abstract public String table()
(可选)存储生成的 ID 值的表格的名称。

默认为持久性提供者选择的名称。

英文文档:

table

public abstract String table
(Optional) Name of table that stores the generated id values.

Defaults to a name chosen by persistence provider.

Default:
""

abstract public String catalog()
(可选)表格的种类。

默认为默认种类。

英文文档:

catalog

public abstract String catalog
(Optional) The catalog of the table.

Defaults to the default catalog.

Default:
""

abstract public String schema()
(可选)表格的模式。

默认为用户的默认模式。

英文文档:

schema

public abstract String schema
(Optional) The schema of the table.

Defaults to the default schema for user.

Default:
""

abstract public String pkColumnName()
(可选)表格中的主键列的名称。

默认为提供者选择的名称。

英文文档:

pkColumnName

public abstract String pkColumnName
(Optional) Name of the primary key column in the table.

Defaults to a provider-chosen name.

Default:
""

abstract public String valueColumnName()
(可选)存储最后一个生成值的列的名称。

默认为提供者选择的名称。

英文文档:

valueColumnName

public abstract String valueColumnName
(Optional) Name of the column that stores the last value generated.

Defaults to a provider-chosen name.

Default:
""

abstract public String pkColumnValue()
(可选)生成器表格中的主键值,它使这组生成值区别于可能存储在表格中的其他值。

默认为将提供者选择的值存储在生成器表格的主键列

英文文档:

pkColumnValue

public abstract String pkColumnValue
(Optional) The primary key value in the generator table that distinguishes this set of generated values from others that may be stored in the table.

Defaults to a provider-chosen value to store in the primary key column of the generator table

Default:
""

abstract public int initialValue()
(可选)从生成器分配 ID 编号时要使用的初始值。
英文文档:

initialValue

public abstract int initialValue
(Optional) The initial value to be used when allocating id numbers from the generator.

Default:
0

abstract public int allocationSize()
(可选)从生成器分配 ID 编号时递增的量。
英文文档:

allocationSize

public abstract int allocationSize
(Optional) The amount to increment by when allocating id numbers from the generator.

Default:
50

abstract public UniqueConstraint[] uniqueConstraints()
(可选)对表格设置的唯一约束。仅当表格生成生效时使用。除了主键约束之外,还将应用这些约束。

默认为无额外限制。

英文文档:

uniqueConstraints

public abstract UniqueConstraint[] uniqueConstraints
(Optional) Unique constraints that are to be placed on the table. These are only used if table generation is in effect. These constraints apply in addition to primary key constraints.

Defaults to no additional constraints.

Default:
{}


Submit a bug or feature

Copyright 2007 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.

一看就知道只有菜鸟才干这么无知的事啦。

PS : 未经我党受权你也可自由散发此文档。 如有任何错误请自行修正;若因此而造成任何损失请直接找人民主席,请勿与本人联系。谢谢!