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.RetentionPolicy.RUNTIME;
017import static javax.persistence.GenerationType.AUTO;
018
019/**
020 * Provides for the specification of generation strategies for the
021 * values of primary keys.
022 * <p>
023 * <p> The <code>GeneratedValue</code> annotation
024 * may be applied to a primary key property or field of an entity or
025 * mapped superclass in conjunction with the {@link Id} annotation.
026 * The use of the <code>GeneratedValue</code> annotation is only
027 * required to be supported for simple primary keys.  Use of the
028 * <code>GeneratedValue</code> annotation is not supported for derived
029 * primary keys.
030 * <p>
031 * <pre>
032 *
033 *     Example 1:
034 *
035 *     &#064;Id
036 *     &#064;GeneratedValue(strategy=SEQUENCE, generator="CUST_SEQ")
037 *     &#064;Column(name="CUST_ID")
038 *     Long id;
039 *
040 * </pre>
041 *
042 * @see Id
043 * @see TableGenerator
044 * @see SequenceGenerator
045 * @since Java Persistence 1.0
046 */
047@Target({FIELD})
048@Retention(RUNTIME)
049
050public @interface GeneratedValue {
051
052  /**
053   * (Optional) The primary key generation strategy
054   * that the persistence provider must use to
055   * generate the annotated entity primary key.
056   *
057   * @return strategy
058   */
059  GenerationType strategy() default AUTO;
060
061  /**
062   * (Optional) The name of the primary key generator
063   * to use as specified in the {@link SequenceGenerator}
064   * or {@link TableGenerator} annotation.
065   * <p> Defaults to the id generator supplied by persistence provider.
066   *
067   * @return generator
068   */
069  String generator() default "";
070}