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