KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > persistence > GeneratedValue


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 JavaDoc;
24 import java.lang.annotation.Retention JavaDoc;
25 import static java.lang.annotation.ElementType.FIELD JavaDoc;
26 import static java.lang.annotation.ElementType.METHOD JavaDoc;
27 import static java.lang.annotation.RetentionPolicy.RUNTIME JavaDoc;
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  * &#064;Id
42  * &#064;GeneratedValue(strategy=SEQUENCE, generator="CUST_SEQ")
43  * &#064;Column(name="CUST_ID")
44  * public Long getId() { return id; }
45  *
46  * Example 2:
47  *
48  * &#064;Id
49  * &#064;GeneratedValue(strategy=TABLE, generator="CUST_GEN")
50  * &#064;Column(name="CUST_ID")
51  * Long id;
52  * </pre>
53  *
54  * @since Java Persistence 1.0
55  */

56 @Target JavaDoc({METHOD, FIELD})
57 @Retention JavaDoc(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 JavaDoc generator() default "";
75 }
76
Popular Tags