KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > persistence > JoinColumn


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 static java.lang.annotation.ElementType.FIELD JavaDoc;
28 import static java.lang.annotation.ElementType.METHOD JavaDoc;
29 import static java.lang.annotation.RetentionPolicy.RUNTIME JavaDoc;
30
31 /**
32  * Is used to specify a mapped column for joining an entity association.
33  *
34  * <pre>
35  * Example:
36  *
37  * &#064;ManyToOne
38  * &#064;JoinColumn(name="ADDR_ID")
39  * public Address getAddress() { return address; }
40  * </pre>
41  *
42  * @since Java Persistence 1.0
43  */

44 @Target JavaDoc({METHOD, FIELD})
45 @Retention JavaDoc(RUNTIME)
46
47 public @interface JoinColumn {
48
49     /**
50      * (Optional) The name of the foreign key column.
51      * The table in which it is found depends upon the
52      * context. If the join is for a OneToOne or Many-
53      * ToOne mapping, the foreign key column is in the
54      * table of the source entity. If the join is for a
55      * ManyToMany, the foreign key is in a join table.
56      *
57      * Default (only applies if a single join column is used):
58      * The concatenation of the following: the name of the
59      * referencing relationship property or field of the referencing
60      * entity; "_"; the name of the referenced primary key column.
61      * If there is no such referencing relationship property or
62      * field in the entity, the join column name is formed as the
63      * concatenation of the following: the name of the entity; "_";
64      * the name of the referenced primary key column.
65      */

66     String JavaDoc name() default "";
67
68     /**
69      * (Optional) The name of the column referenced
70      * by this foreign key column. When used with
71      * relationship mappings, the referenced column is
72      * in the table of the target entity. When used inside
73      * a JoinTable annotation, the referenced key column
74      * is in the entity table of the owning entity, or
75      * inverse entity if the join is part of the inverse join
76      * definition.
77      *
78      * Default (only applies if single join column is being
79      * used): The same name as the primary key column of the
80      * referenced table.
81      */

82     String JavaDoc referencedColumnName() default "";
83
84     /**
85      * (Optional) Whether the property is a unique key.
86      * This is a shortcut for the UniqueConstraint annotation
87      * at the table level and is useful for when the
88      * unique key constraint is only a single field. It is
89      * not necessary to explicitly specify this for a join
90      * column that corresponds to a primary key that is
91      * part of a foreign key.
92      */

93     boolean unique() default false;
94
95     /** (Optional) Whether the foreign key column is nullable. */
96     boolean nullable() default true;
97
98     /**
99      * (Optional) Whether the column is included in
100      * SQL INSERT statements generated by the persistence
101      * provider.
102      */

103     boolean insertable() default true;
104
105     /**
106      * (Optional) Whether the column is included in
107      * SQL UPDATE statements generated by the persistence
108      * provider.
109      */

110     boolean updatable() default true;
111
112     /**
113      * (Optional) The SQL fragment that is used when
114      * generating the DDL for the column.
115      * <p> Defaults to the generated SQL for the column.
116      */

117     String JavaDoc columnDefinition() default "";
118
119     /**
120      * (Optional) The name of the table that contains
121      * the column. If a table is not specified, the column
122      * is assumed to be in the primary table of the
123      * applicable entity.
124      */

125     String JavaDoc table() default "";
126 }
127
Popular Tags