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 static java.lang.annotation.ElementType.TYPE;
041: import static java.lang.annotation.RetentionPolicy.RUNTIME;
042:
043: /**
044: * This annotation is used to specify a secondary table for
045: * the annotated entity class. Specifying one or more secondary
046: * tables indicates that the data for the entity class is stored
047: * across multiple tables.
048: *
049: * <p> If no <code>SecondaryTable</code> annotation is specified,
050: * it is assumed that all persistent fields or properties of the
051: * entity are mapped to the primary table. If no primary key join
052: * columns are specified, the join columns are assumed to reference
053: * the primary key columns of the primary table, and have the same
054: * names and types as the referenced primary key columns of the
055: * primary table.
056: *
057: * <pre>
058: * Example 1: Single secondary table with a single primary key column.
059: *
060: * @Entity
061: * @Table(name="CUSTOMER")
062: * @SecondaryTable(name="CUST_DETAIL",
063: * pkJoinColumns=@PrimaryKeyJoinColumn(name="CUST_ID"))
064: * public class Customer { ... }
065: *
066: * Example 2: Single secondary table with multiple primary key columns.
067: *
068: * @Entity
069: * @Table(name="CUSTOMER")
070: * @SecondaryTable(name="CUST_DETAIL",
071: * pkJoinColumns={
072: * @PrimaryKeyJoinColumn(name="CUST_ID"),
073: * @PrimaryKeyJoinColumn(name="CUST_TYPE")})
074: * public class Customer { ... }
075: * </pre>
076: *
077: * @since Java Persistence 1.0
078: */
079: @Target(TYPE)
080: @Retention(RUNTIME)
081: public @interface SecondaryTable {
082:
083: /** (Required) The name of the table. */
084: String name();
085:
086: /** (Optional) The catalog of the table.
087: * <p> Defaults to the default catalog.
088: */
089: String catalog() default "";
090:
091: /** (Optional) The schema of the table.
092: * <p> Defaults to the default schema for user.
093: */
094: String schema() default "";
095:
096: /**
097: * (Optional) The columns that are used to join with
098: * the primary table.
099: * <p> Defaults to the column(s) of the same name(s)
100: * as the primary key column(s) in the primary table
101: */
102: PrimaryKeyJoinColumn[] pkJoinColumns() default {};
103:
104: /**
105: * (Optional) Unique constraints that are to be placed on the
106: * table. These are typically only used if table generation
107: * is in effect. These constraints apply in addition to any
108: * constraints specified by the {@link Column} and {@link JoinColumn}
109: * annotations and constraints entailed by primary key mappings.
110: * <p> Defaults to no additional constraints.
111: */
112: UniqueConstraint[] uniqueConstraints() default {};
113: }
|