001/* 002 * Copyright (c) 2008, 2009, 2011 Oracle, Inc. All rights reserved. 003 * 004 * This program and the accompanying materials are made available under the 005 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0 006 * which accompanies this distribution. The Eclipse Public License is available 007 * at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License 008 * is available at http://www.eclipse.org/org/documents/edl-v10.php. 009 */ 010package javax.persistence; 011 012import java.lang.annotation.Retention; 013import java.lang.annotation.Target; 014 015import static java.lang.annotation.ElementType.FIELD; 016import static java.lang.annotation.ElementType.METHOD; 017import static java.lang.annotation.RetentionPolicy.RUNTIME; 018import static javax.persistence.GenerationType.AUTO; 019 020/** 021 * Provides for the specification of generation strategies for the 022 * values of primary keys. 023 * <p> 024 * <p> The <code>GeneratedValue</code> annotation 025 * may be applied to a primary key property or field of an entity or 026 * mapped superclass in conjunction with the {@link Id} annotation. 027 * The use of the <code>GeneratedValue</code> annotation is only 028 * required to be supported for simple primary keys. Use of the 029 * <code>GeneratedValue</code> annotation is not supported for derived 030 * primary keys. 031 * <p> 032 * <pre> 033 * 034 * Example 1: 035 * 036 * @Id 037 * @GeneratedValue(strategy=SEQUENCE, generator="CUST_SEQ") 038 * @Column(name="CUST_ID") 039 * public Long getId() { return id; } 040 * 041 * Example 2: 042 * 043 * @Id 044 * @GeneratedValue(strategy=TABLE, generator="CUST_GEN") 045 * @Column(name="CUST_ID") 046 * Long id; 047 * </pre> 048 * 049 * @see Id 050 * @see TableGenerator 051 * @see SequenceGenerator 052 * @since Java Persistence 1.0 053 */ 054@Target({METHOD, FIELD}) 055@Retention(RUNTIME) 056 057public @interface GeneratedValue { 058 059 /** 060 * (Optional) The primary key generation strategy 061 * that the persistence provider must use to 062 * generate the annotated entity primary key. 063 * 064 * @return strategy 065 */ 066 GenerationType strategy() default AUTO; 067 068 /** 069 * (Optional) The name of the primary key generator 070 * to use as specified in the {@link SequenceGenerator} 071 * or {@link TableGenerator} annotation. 072 * <p> Defaults to the id generator supplied by persistence provider. 073 * 074 * @return generator 075 */ 076 String generator() default ""; 077}