1 /* 2 * The contents of this file are subject to the terms 3 * of the Common Development and Distribution License 4 * (the "License"). You may not use this file except 5 * in compliance with the License. 6 * 7 * You can obtain a copy of the license at 8 * glassfish/bootstrap/legal/CDDLv1.0.txt or 9 * https://glassfish.dev.java.net/public/CDDLv1.0.html. 10 * See the License for the specific language governing 11 * permissions and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL 14 * HEADER in each file and include the License file at 15 * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable, 16 * add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your 18 * own identifying information: Portions Copyright [yyyy] 19 * [name of copyright owner] 20 */ 21 package javax.persistence; 22 23 import java.lang.annotation.Target; 24 import java.lang.annotation.Retention; 25 import static java.lang.annotation.ElementType.FIELD; 26 import static java.lang.annotation.ElementType.METHOD; 27 import static java.lang.annotation.RetentionPolicy.RUNTIME; 28 import static javax.persistence.GenerationType.AUTO; 29 30 /** 31 * Provides for the specification of generation strategies for 32 * the values of primary keys. The <code>GeneratedValue</code> 33 * annotation may be applied to a primary key property or 34 * field of an entity or mapped superclass in conjunction with 35 * the {@link Id} annotation. 36 * 37 * <pre> 38 * 39 * Example 1: 40 * 41 * @Id 42 * @GeneratedValue(strategy=SEQUENCE, generator="CUST_SEQ") 43 * @Column(name="CUST_ID") 44 * public Long getId() { return id; } 45 * 46 * Example 2: 47 * 48 * @Id 49 * @GeneratedValue(strategy=TABLE, generator="CUST_GEN") 50 * @Column(name="CUST_ID") 51 * Long id; 52 * </pre> 53 * 54 * @since Java Persistence 1.0 55 */ 56 @Target({METHOD, FIELD}) 57 @Retention(RUNTIME) 58 59 public @interface GeneratedValue { 60 61 /** 62 * (Optional) The primary key generation strategy 63 * that the persistence provider must use to 64 * generate the annotated entity primary key. 65 */ 66 GenerationType strategy() default AUTO; 67 68 /** 69 * (Optional) The name of the primary key generator 70 * to use as specified in the {@link SequenceGenerator} 71 * or {@link TableGenerator} annotation. 72 * <p> Defaults to the id generator supplied by persistence provider. 73 */ 74 String generator() default ""; 75 } 76