KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > persistence > OneToOne


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.METHOD JavaDoc;
29 import static java.lang.annotation.ElementType.FIELD 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
35  * another entity that has one-to-one multiplicity. It is not
36  * normally necessary to specify the associated target entity
37  * explicitly since it can usually be inferred from the type
38  * of the object being referenced.
39  *
40  * <pre>
41  * Example 1: One-to-one association that maps a foreign key column
42  *
43  * On Customer class:
44  *
45  * &#064;OneToOne(optional=false)
46  * &#064;JoinColumn(
47  * name="CUSTREC_ID", unique=true, nullable=false, updatable=false)
48  * public CustomerRecord getCustomerRecord() { return customerRecord; }
49  *
50  * On CustomerRecord class:
51  *
52  * &#064;OneToOne(optional=false, mappedBy="customerRecord")
53  * public Customer getCustomer() { return customer; }
54  *
55  * Example 2: One-to-one association that assumes both the source and target share the same primary key values.
56  *
57  * On Employee class:
58  *
59  * &#064;Entity
60  * public class Employee {
61  * &#064;Id Integer id;
62  *
63  * &#064;OneToOne &#064;PrimaryKeyJoinColumn
64  * EmployeeInfo info;
65  * ...
66  * }
67  *
68  * On EmployeeInfo class:
69  *
70  * &#064;Entity
71  * public class EmployeeInfo {
72  * &#064;Id Integer id;
73  * ...
74  * }
75  * </pre>
76  *
77  * @since Java Persistence 1.0
78  */

79 @Target JavaDoc({METHOD, FIELD})
80 @Retention JavaDoc(RUNTIME)
81
82 public @interface OneToOne {
83
84     /**
85      * (Optional) The entity class that is the target of
86      * the association.
87      *
88      * <p> Defaults to the type of the field or property
89      * that stores the association.
90      */

91     Class JavaDoc targetEntity() default void.class;
92
93     /**
94      * (Optional) The operations that must be cascaded to
95      * the target of the association.
96      *
97      * <p> By default no operations are cascaded.
98      */

99     CascadeType[] cascade() default {};
100
101     /**
102      * (Optional) Whether the association should be lazily
103      * loaded or must be eagerly fetched. The {@link FetchType#EAGER EAGER}
104      * strategy is a requirement on the persistence provider runtime that
105      * the associated entity must be eagerly fetched. The {@link FetchType#LAZY
106      * LAZY} strategy is a hint to the persistence provider runtime.
107      */

108     FetchType fetch() default EAGER;
109
110     /**
111      * (Optional) Whether the association is optional. If set
112      * to false then a non-null relationship must always exist.
113      */

114     boolean optional() default true;
115
116     /** (Optional) The field that owns the relationship. This
117       * element is only specified on the inverse (non-owning)
118       * side of the association.
119      */

120     String JavaDoc mappedBy() default "";
121 }
122
Popular Tags