GeneratedValue (Java EE 5)

Java EE API


javax.persistence Annotation Type GeneratedValue


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

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

供主键值的生成战略规范使用。GeneratedValue 注释可以与 Id 注释一起应用于实体或映射的超类的主键属性或字段。
示例 1:


     @Id
     @GeneratedValue(strategy=SEQUENCE, generator="CUST_SEQ")
     @Column(name="CUST_ID")
     public Long getId() { return id; }


示例 2:

     @Id
     @GeneratedValue(strategy=TABLE, generator="CUST_GEN")
     @Column(name="CUST_ID")
     Long id;
 
英文文档:

Provides for the specification of generation strategies for the values of primary keys. The GeneratedValue annotation may be applied to a primary key property or field of an entity or mapped superclass in conjunction with the Id annotation.

 Example 1:

     @Id
     @GeneratedValue(strategy=SEQUENCE, generator="CUST_SEQ")
     @Column(name="CUST_ID")
     public Long getId() { return id; }

     Example 2:

     @Id
     @GeneratedValue(strategy=TABLE, generator="CUST_GEN")
     @Column(name="CUST_ID")
     Long id;
 

Since:
Java Persistence 1.0

Optional Element Summary
 String
 GenerationType
 

abstract public GenerationType strategy()
(可选)主键生成战略,持久性提供者必须使用该战略生成带注释的实体主键。
英文文档:

strategy

public abstract GenerationType strategy
(Optional) The primary key generation strategy that the persistence provider must use to generate the annotated entity primary key.

Default:
AUTO

abstract public String generator()
(可选)SequenceGeneratorTableGenerator 注释中指定使用的主键生成器的名称。

默认为持久性提供者提供的 ID 生成器。

英文文档:

generator

public abstract String generator
(Optional) The name of the primary key generator to use as specified in the SequenceGenerator or TableGenerator annotation.

Defaults to the id generator supplied by persistence provider.

Default:
""


Submit a bug or feature

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

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

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