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.METHOD;
041: import static java.lang.annotation.ElementType.FIELD;
042: import static java.lang.annotation.ElementType.TYPE;
043: import static java.lang.annotation.RetentionPolicy.RUNTIME;
044:
045: /**
046: * This annotation specifies a primary key column that is used
047: * as a foreign key to join to another table.
048: *
049: * <p> It is used to join the primary table of an entity subclass
050: * in the {@link InheritanceType#JOINED JOINED} mapping strategy
051: * to the primary table of its superclass; it is used within a
052: * {@link SecondaryTable} annotation to join a secondary table
053: * to a primary table; and it may be used in a {@link OneToOne}
054: * mapping in which the primary key of the referencing entity
055: * is used as a foreign key to the referenced entity.
056: *
057: * <p> If no <code>PrimaryKeyJoinColumn</code> annotation is
058: * specified for a subclass in the {@link InheritanceType#JOINED
059: * JOINED} mapping strategy, the foreign key columns are assumed
060: * to have the same names as the primary key columns of the
061: * primary table of the superclass
062: *
063: * <pre>
064: *
065: * Example: Customer and ValuedCustomer subclass
066: *
067: * @Entity
068: * @Table(name="CUST")
069: * @Inheritance(strategy=JOINED)
070: * @DiscriminatorValue("CUST")
071: * public class Customer { ... }
072: *
073: * @Entity
074: * @Table(name="VCUST")
075: * @DiscriminatorValue("VCUST")
076: * @PrimaryKeyJoinColumn(name="CUST_ID")
077: * public class ValuedCustomer extends Customer { ... }
078: * </pre>
079: *
080: * @since Java Persistence 1.0
081: */
082: @Target({TYPE,METHOD,FIELD})
083: @Retention(RUNTIME)
084: public @interface PrimaryKeyJoinColumn {
085:
086: /**
087: * The name of the primary key column of the current table.
088: * <p> Defaults to the same name as the primary key column
089: * of the primary table of the superclass ({@link
090: * InheritanceType#JOINED JOINED} mapping strategy); the same
091: * name as the primary key column of the primary table
092: * ({@link SecondaryTable} mapping); or the same name as the
093: * primary key column for the table for the referencing entity
094: * ({@link OneToOne} mapping)
095: */
096: String name() default "";
097:
098: /**
099: * (Optional) The name of the primary key column of the table
100: * being joined to.
101: * <p> Defaults to the same name as the primary key column
102: * of the primary table of the superclass ({@link
103: * InheritanceType#JOINED JOINED} mapping strategy); the same
104: * name as the primary key column of the primary table
105: * ({@link SecondaryTable} mapping); or the same name as the
106: * primary key column for the table for the referencing entity
107: * ({@link OneToOne} mapping)
108: */
109: String referencedColumnName() default "";
110:
111: /**
112: * (Optional) The SQL fragment that is used when generating the
113: * DDL for the column. This should not be specified for a
114: * {@link OneToOne} primary key association.
115: * <p> Defaults to the generated SQL to create a column of the
116: * inferred type.
117: */
118: String columnDefinition() default "";
119: }
|