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.RetentionPolicy.RUNTIME; 017 018/** 019 * Defines mapping for composite foreign keys. This annotation 020 * groups <code>JoinColumn</code> annotations for the same relationship. 021 * <p> 022 * <p> When the <code>JoinColumns</code> annotation is used, 023 * both the <code>name</code> and the <code>referencedColumnName</code> elements 024 * must be specified in each such <code>JoinColumn</code> annotation. 025 * <p> 026 * <pre> 027 * 028 * Example: 029 * @ManyToOne 030 * @JoinColumns({ 031 * @JoinColumn(name="ADDR_ID", referencedColumnName="ID"), 032 * @JoinColumn(name="ADDR_ZIP", referencedColumnName="ZIP") 033 * }) 034 * public Address getAddress() { return address; } 035 * </pre> 036 * 037 * @see JoinColumn 038 * @since Java Persistence 1.0 039 */ 040@Target({FIELD}) 041@Retention(RUNTIME) 042public @interface JoinColumns { 043 JoinColumn[] value(); 044 045 /** 046 * (Optional) The foreign key constraint specification for the join columns. This is used only if table 047 * generation is in effect. Default is provider defined. 048 * 049 * @return The foreign key specification 050 */ 051 ForeignKey foreignKey() default @ForeignKey(); 052}