KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > persistence > OneToMany


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.LAZY;
32
33 /**
34  * Defines a many-valued association with one-to-many multiplicity.
35  *
36  * <p> If the collection is defined using generics to specify the
37  * element type, the associated target entity type need not be
38  * specified; otherwise the target entity class must be specified.
39  *
40  * <pre>
41  *
42  * Example 1: One-to-Many association using generics
43  *
44  * In Customer class:
45  *
46  * &#064;OneToMany(cascade=ALL, mappedBy="customer")
47  * public Set<Order> getOrders() { return orders; }
48  *
49  * In Order class:
50  *
51  * &#064;ManyToOne
52  * &#064;JoinColumn(name="CUST_ID", nullable=false)
53  * public Customer getCustomer() { return customer; }
54  *
55  * Example 2: One-to-Many association without using generics
56  *
57  * In Customer class:
58  *
59  * &#064;OneToMany(targetEntity=com.acme.Order.class, cascade=ALL,
60  * mappedBy="customer")
61  * public Set getOrders() { return orders; }
62  *
63  * In Order class:
64  *
65  * &#064;ManyToOne
66  * &#064;JoinColumn(name="CUST_ID", nullable=false)
67  * public Customer getCustomer() { return customer; }
68  * </pre>
69  *
70  * @since Java Persistence 1.0
71  */

72 @Target JavaDoc({METHOD, FIELD})
73 @Retention JavaDoc(RUNTIME)
74
75 public @interface OneToMany {
76
77     /**
78      * (Optional) The entity class that is the target
79      * of the association. Optional only if the collection
80      * property is defined using Java generics.
81      * Must be specified otherwise.
82      *
83      * <p> Defaults to the parameterized type of
84      * the collection when defined using generics.
85      */

86     Class JavaDoc targetEntity() default void.class;
87
88     /**
89      * (Optional) The operations that must be cascaded to
90      * the target of the association.
91      * <p> Defaults to no operations being cascaded.
92      */

93     CascadeType[] cascade() default {};
94
95     /** (Optional) Whether the association should be
96      * lazily loaded or must be eagerly fetched. The
97      * {@link FetchType#EAGER EAGER} strategy is a
98      * requirement on the persistenceprovider runtime
99      * that the associatedentities must be eagerly fetched.
100      * The {@link FetchType#LAZY LAZY} strategy is a hint
101      * to the persistence provider runtime.
102      */

103     FetchType fetch() default LAZY;
104
105     /**
106      * The field that owns the relationship. Required unless
107      * the relationship is unidirectional.
108      */

109     String JavaDoc mappedBy() default "";
110 }
111
Popular Tags