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 * Applied to a persistent field or property of an entity 021 * class or mapped superclass to denote a composite primary 022 * key that is an embeddable class. The embeddable class 023 * must be annotated as {@link Embeddable}. 024 * <p> 025 * <p> There must be only one <code>EmbeddedId</code> annotation and 026 * no <code>Id</code> annotation when the <code>EmbeddedId</code> annotation is used. 027 * <p> 028 * <p> The {@link AttributeOverride} annotation may be used to override 029 * the column mappings declared within the embeddable class. 030 * <p> 031 * <p> The {@link MapsId} annotation may be used in conjunction 032 * with the <code>EmbeddedId</code> annotation to specify a derived 033 * primary key. 034 * <p> 035 * <p> If the entity has a derived primary key, the 036 * <code>AttributeOverride</code> annotation may only be used to 037 * override those attributes of the embedded id that do not correspond 038 * to the relationship to the parent entity. 039 * <p> 040 * <p> Relationship mappings defined within an embedded id class are not supported. 041 * <p> 042 * <pre> 043 * Example 1: 044 * 045 * @EmbeddedId 046 * protected EmployeePK empPK; 047 * 048 * 049 * Example 2: 050 * 051 * @Embeddable 052 * public class DependentId { 053 * String name; 054 * EmployeeId empPK; // corresponds to primary key type of Employee 055 * } 056 * 057 * @Entity 058 * public class Dependent { 059 * // default column name for "name" attribute is overridden 060 * @AttributeOverride(name="name", @Column(name="dep_name")) 061 * @EmbeddedId DependentId id; 062 * ... 063 * @MapsId("empPK") 064 * @ManyToOne Employee emp; 065 * } 066 * </pre> 067 * 068 * @see Embeddable 069 * @see MapsId 070 * @since Java Persistence 1.0 071 */ 072@Target({METHOD, FIELD}) 073@Retention(RUNTIME) 074public @interface EmbeddedId { 075}