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 */
010
011// $Id: $
012
013package javax.persistence;
014
015import java.lang.annotation.Retention;
016import java.lang.annotation.Target;
017
018import static java.lang.annotation.ElementType.FIELD;
019import static java.lang.annotation.RetentionPolicy.RUNTIME;
020import static javax.persistence.EnumType.ORDINAL;
021
022/**
023 * Specifies the enum type for a map key whose basic type is an enumerated type. The
024 * <code>MapKeyEnumerated</code> annotation can be applied to an element collection or relationship of type
025 * <code>java.util.Map</code>, in conjunction with the <code>ElementCollection</code>, <code>OneToMany</code>,
026 * or <code>ManyToMany</code> annotation. If the enumerated type is not specified or the
027 * <code>MapKeyEnumerated</code> annotation is not used, the enumerated type is assumed to be
028 * <code>ORDINAL</code>.
029 * <p>
030 * <pre>
031 *   Example:
032 *
033 *   public enum ProjectStatus {COMPLETE, DELAYED, CANCELLED, IN_PROGRESS}
034 *
035 *   public enum SalaryRate {JUNIOR, SENIOR, MANAGER, EXECUTIVE}
036 *
037 *   &#064;Entity public class Employee {
038 *       &#064;ManyToMany
039 *       public Projects&#060;ProjectStatus, Project&#062; getProjects() {...}
040 *
041 *       &#064;OneToMany
042 *       &#064;MapKeyEnumerated(STRING)
043 *       public Map&#060;SalaryRate, Employee&#062; getEmployees() {...}
044 *       ...
045 *   }
046 * </pre>
047 *
048 * @see ElementCollection
049 * @see OneToMany
050 * @see ManyToMany
051 * @since Java Persistence 2.0
052 */
053@Target({FIELD})
054@Retention(RUNTIME)
055public @interface MapKeyEnumerated {
056
057  /**
058   * (Optional) The type used in mapping a map key enum type.
059   *
060   * @return The type
061   */
062  EnumType value() default ORDINAL;
063}