001/*
002 * Copyright (c) 2008, 2009, 2011 Oracle, Inc. All rights reserved.
003 *
004 * This program and the accompanying materials are made available under the
005 * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
006 * which accompanies this distribution.  The Eclipse Public License is available
007 * at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License
008 * is available at http://www.eclipse.org/org/documents/edl-v10.php.
009 */
010package javax.persistence;
011
012import java.lang.annotation.Retention;
013import java.lang.annotation.Target;
014
015import static java.lang.annotation.ElementType.FIELD;
016import static java.lang.annotation.ElementType.METHOD;
017import static java.lang.annotation.RetentionPolicy.RUNTIME;
018
019/**
020 * Defines mapping for composite foreign keys. This annotation
021 * groups <code>JoinColumn</code> annotations for the same relationship.
022 * <p>
023 * <p> When the <code>JoinColumns</code> annotation is used,
024 * both the <code>name</code> and the <code>referencedColumnName</code> elements
025 * must be specified in each such <code>JoinColumn</code> annotation.
026 * <p>
027 * <pre>
028 *
029 *    Example:
030 *    &#064;ManyToOne
031 *    &#064;JoinColumns({
032 *        &#064;JoinColumn(name="ADDR_ID", referencedColumnName="ID"),
033 *        &#064;JoinColumn(name="ADDR_ZIP", referencedColumnName="ZIP")
034 *    })
035 *    public Address getAddress() { return address; }
036 * </pre>
037 *
038 * @see JoinColumn
039 * @since Java Persistence 1.0
040 */
041@Target({METHOD, FIELD})
042@Retention(RUNTIME)
043public @interface JoinColumns {
044  JoinColumn[] value();
045
046  /**
047   * (Optional) The foreign key constraint specification for the join columns. This is used only if table
048   * generation is in effect.  Default is provider defined.
049   *
050   * @return The foreign key specification
051   */
052  ForeignKey foreignKey() default @ForeignKey();
053}