001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036: package javax.persistence;
037:
038: import java.lang.annotation.Target;
039: import java.lang.annotation.Retention;
040: import javax.persistence.CascadeType;
041: import static java.lang.annotation.ElementType.METHOD;
042: import static java.lang.annotation.ElementType.FIELD;
043: import static java.lang.annotation.RetentionPolicy.RUNTIME;
044: import static javax.persistence.FetchType.EAGER;
045:
046: /**
047: * This annotation defines a single-valued association to
048: * another entity that has one-to-one multiplicity. It is not
049: * normally necessary to specify the associated target entity
050: * explicitly since it can usually be inferred from the type
051: * of the object being referenced.
052: *
053: * <pre>
054: * Example 1: One-to-one association that maps a foreign key column
055: *
056: * On Customer class:
057: *
058: * @OneToOne(optional=false)
059: * @JoinColumn(
060: * name="CUSTREC_ID", unique=true, nullable=false, updatable=false)
061: * public CustomerRecord getCustomerRecord() { return customerRecord; }
062: *
063: * On CustomerRecord class:
064: *
065: * @OneToOne(optional=false, mappedBy="customerRecord")
066: * public Customer getCustomer() { return customer; }
067: *
068: * Example 2: One-to-one association that assumes both the source and target share the same primary key values.
069: *
070: * On Employee class:
071: *
072: * @Entity
073: * public class Employee {
074: * @Id Integer id;
075: *
076: * @OneToOne @PrimaryKeyJoinColumn
077: * EmployeeInfo info;
078: * ...
079: * }
080: *
081: * On EmployeeInfo class:
082: *
083: * @Entity
084: * public class EmployeeInfo {
085: * @Id Integer id;
086: * ...
087: * }
088: * </pre>
089: *
090: * @since Java Persistence 1.0
091: */
092: @Target({METHOD,FIELD})
093: @Retention(RUNTIME)
094: public @interface OneToOne {
095:
096: /**
097: * (Optional) The entity class that is the target of
098: * the association.
099: *
100: * <p> Defaults to the type of the field or property
101: * that stores the association.
102: */
103: Class targetEntity() default void.class;
104:
105: /**
106: * (Optional) The operations that must be cascaded to
107: * the target of the association.
108: *
109: * <p> By default no operations are cascaded.
110: */
111: CascadeType[] cascade() default {};
112:
113: /**
114: * (Optional) Whether the association should be lazily
115: * loaded or must be eagerly fetched. The {@link FetchType#EAGER EAGER}
116: * strategy is a requirement on the persistence provider runtime that
117: * the associated entity must be eagerly fetched. The {@link FetchType#LAZY
118: * LAZY} strategy is a hint to the persistence provider runtime.
119: */
120: FetchType fetch() default EAGER;
121:
122: /**
123: * (Optional) Whether the association is optional. If set
124: * to false then a non-null relationship must always exist.
125: */
126: boolean optional() default true;
127:
128: /** (Optional) The field that owns the relationship. This
129: * element is only specified on the inverse (non-owning)
130: * side of the association.
131: */
132: String mappedBy() default "";
133: }
|