KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > persistence > PrimaryKeyJoinColumn


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.METHOD JavaDoc;
28 import static java.lang.annotation.ElementType.FIELD JavaDoc;
29 import static java.lang.annotation.ElementType.TYPE JavaDoc;
30 import static java.lang.annotation.RetentionPolicy.RUNTIME JavaDoc;
31
32 /**
33  * This annotation specifies a primary key column that is used
34  * as a foreign key to join to another table.
35  *
36  * <p> It is used to join the primary table of an entity subclass
37  * in the {@link InheritanceType#JOINED JOINED} mapping strategy
38  * to the primary table of its superclass; it is used within a
39  * {@link SecondaryTable} annotation to join a secondary table
40  * to a primary table; and it may be used in a {@link OneToOne}
41  * mapping in which the primary key of the referencing entity
42  * is used as a foreign key to the referenced entity.
43  *
44  * <p> If no <code>PrimaryKeyJoinColumn</code> annotation is
45  * specified for a subclass in the {@link InheritanceType#JOINED
46  * JOINED} mapping strategy, the foreign key columns are assumed
47  * to have the same names as the primary key columns of the
48  * primary table of the superclass
49  *
50  * <pre>
51  *
52  * Example: Customer and ValuedCustomer subclass
53  *
54  * &#064;Entity
55  * &#064;Table(name="CUST")
56  * &#064;Inheritance(strategy=JOINED)
57  * &#064;DiscriminatorValue("CUST")
58  * public class Customer { ... }
59  *
60  * &#064;Entity
61  * &#064;Table(name="VCUST")
62  * &#064;DiscriminatorValue("VCUST")
63  * &#064;PrimaryKeyJoinColumn(name="CUST_ID")
64  * public class ValuedCustomer extends Customer { ... }
65  * </pre>
66  *
67  * @since Java Persistence 1.0
68  */

69 @Target JavaDoc({TYPE, METHOD, FIELD})
70 @Retention JavaDoc(RUNTIME)
71
72 public @interface PrimaryKeyJoinColumn {
73
74     /**
75      * The name of the primary key column of the current table.
76      * <p> Defaults to the same name as the primary key column
77      * of the primary table of the superclass ({@link
78      * InheritanceType#JOINED JOINED} mapping strategy); the same
79      * name as the primary key column of the primary table
80      * ({@link SecondaryTable} mapping); or the same name as the
81      * primary key column for the table for the referencing entity
82      * ({@link OneToOne} mapping)
83      */

84     String JavaDoc name() default "";
85
86     /**
87      * (Optional) The name of the primary key column of the table
88      * being joined to.
89      * <p> Defaults to the same name as the primary key column
90      * of the primary table of the superclass ({@link
91      * InheritanceType#JOINED JOINED} mapping strategy); the same
92      * name as the primary key column of the primary table
93      * ({@link SecondaryTable} mapping); or the same name as the
94      * primary key column for the table for the referencing entity
95      * ({@link OneToOne} mapping)
96      */

97     String JavaDoc referencedColumnName() default "";
98
99     /**
100      * (Optional) The SQL fragment that is used when generating the
101      * DDL for the column. This should not be specified for a
102      * {@link OneToOne} primary key association.
103      * <p> Defaults to the generated SQL to create a column of the
104      * inferred type.
105      */

106     String JavaDoc columnDefinition() default "";
107 }
108
Popular Tags