KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > persistence > SecondaryTable


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.TYPE JavaDoc;
28 import static java.lang.annotation.RetentionPolicy.RUNTIME JavaDoc;
29
30 /**
31  * This annotation is used to specify a secondary table for
32  * the annotated entity class. Specifying one or more secondary
33  * tables indicates that the data for the entity class is stored
34  * across multiple tables.
35  *
36  * <p> If no <code>SecondaryTable</code> annotation is specified,
37  * it is assumed that all persistent fields or properties of the
38  * entity are mapped to the primary table. If no primary key join
39  * columns are specified, the join columns are assumed to reference
40  * the primary key columns of the primary table, and have the same
41  * names and types as the referenced primary key columns of the
42  * primary table.
43  *
44  * <pre>
45  * Example 1: Single secondary table with a single primary key column.
46  *
47  * &#064;Entity
48  * &#064;Table(name="CUSTOMER")
49  * &#064;SecondaryTable(name="CUST_DETAIL",
50  * pkJoinColumns=&#064;PrimaryKeyJoinColumn(name="CUST_ID"))
51  * public class Customer { ... }
52  *
53  * Example 2: Single secondary table with multiple primary key columns.
54  *
55  * &#064;Entity
56  * &#064;Table(name="CUSTOMER")
57  * &#064;SecondaryTable(name="CUST_DETAIL",
58  * pkJoinColumns={
59  * &#064;PrimaryKeyJoinColumn(name="CUST_ID"),
60  * &#064;PrimaryKeyJoinColumn(name="CUST_TYPE")})
61  * public class Customer { ... }
62  * </pre>
63  *
64  * @since Java Persistence 1.0
65  */

66 @Target JavaDoc(TYPE)
67 @Retention JavaDoc(RUNTIME)
68
69 public @interface SecondaryTable {
70
71     /** (Required) The name of the table. */
72     String JavaDoc name();
73
74     /** (Optional) The catalog of the table.
75      * <p> Defaults to the default catalog.
76      */

77     String JavaDoc catalog() default "";
78
79     /** (Optional) The schema of the table.
80      * <p> Defaults to the default schema for user.
81      */

82     String JavaDoc schema() default "";
83
84     /**
85      * (Optional) The columns that are used to join with
86      * the primary table.
87      * <p> Defaults to the column(s) of the same name(s)
88      * as the primary key column(s) in the primary table
89      */

90     PrimaryKeyJoinColumn[] pkJoinColumns() default {};
91
92     /**
93      * (Optional) Unique constraints that are to be placed on the
94      * table. These are typically only used if table generation
95      * is in effect. These constraints apply in addition to any
96      * constraints specified by the {@link Column} and {@link JoinColumn}
97      * annotations and constraints entailed by primary key mappings.
98      * <p> Defaults to no additional constraints.
99      */

100     UniqueConstraint[] uniqueConstraints() default {};
101 }
102
Popular Tags