KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > persistence > ManyToOne


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 in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
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 Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package javax.persistence;
24
25 import java.lang.annotation.Target JavaDoc;
26 import java.lang.annotation.Retention JavaDoc;
27 import javax.persistence.CascadeType;
28 import static java.lang.annotation.ElementType.FIELD JavaDoc;
29 import static java.lang.annotation.ElementType.METHOD JavaDoc;
30 import static java.lang.annotation.RetentionPolicy.RUNTIME JavaDoc;
31 import static javax.persistence.FetchType.EAGER;
32
33 /**
34  * This annotation defines a single-valued association to another
35  * entity class that has many-to-one multiplicity. It is not normally
36  * necessary to specify the target entity explicitly since it can
37  * usually be inferred from the type of the object being referenced.
38  *
39  * <pre>
40  *
41  * Example:
42  *
43  * &#064;ManyToOne(optional=false)
44  * &#064;JoinColumn(name="CUST_ID", nullable=false, updatable=false)
45  * public Customer getCustomer() { return customer; }
46  * </pre>
47  *
48  * @since Java Persistence 1.0
49  */

50 @Target JavaDoc({METHOD, FIELD})
51 @Retention JavaDoc(RUNTIME)
52
53 public @interface ManyToOne {
54
55     /**
56      * (Optional) The entity class that is the target of
57      * the association.
58      *
59      * <p> Defaults to the type of the field or property
60      * that stores the association.
61      */

62     Class JavaDoc targetEntity() default void.class;
63
64     /**
65      * (Optional) The operations that must be cascaded to
66      * the target of the association.
67      *
68      * <p> By default no operations are cascaded.
69      */

70     CascadeType[] cascade() default {};
71
72     /**
73      * (Optional) Whether the association should be lazily
74      * loaded or must be eagerly fetched. The {@link FetchType#EAGER EAGER}
75      * strategy is a requirement on the persistence provider runtime that
76      * the associated entity must be eagerly fetched. The {@link FetchType#LAZY
77      * LAZY} strategy is a hint to the persistence provider runtime.
78      */

79     FetchType fetch() default EAGER;
80
81     /**
82      * (Optional) Whether the association is optional. If set
83      * to false then a non-null relationship must always exist.
84      */

85     boolean optional() default true;
86 }
87
Popular Tags