javax.persistence.MapKeyClass Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javax.persistence Show documentation
Show all versions of javax.persistence Show documentation
The Java Persistence API (JPA) : a standard interface-based Java model abstraction of persistence, developed by the JCP.
/*
* Copyright (c) 2008, 2009, 2011 Oracle, Inc. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution. The Eclipse Public License is available
* at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License
* is available at http://www.eclipse.org/org/documents/edl-v10.php.
*/
package javax.persistence;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Specifies the type of the map key for associations of type java.util.Map
. The map key can be a
* basic type, an embeddable class, or an entity. If the map is specified using Java generics, the
* MapKeyClass
annotation and associated type need not be specified; otherwise they must be
* specified.
*
* The MapKeyClass
annotation is used in conjunction with ElementCollection
or one
* of the collection-valued relationship annotations (OneToMany
or ManyToMany
). The
* MapKey
annotation is not used when MapKeyClass
is specified and vice versa.
*
*
*
* Example 1:
*
* @Entity
* public class Item {
* @Id int id;
* ...
* @ElementCollection(targetClass=String.class)
* @MapKeyClass(String.class)
* Map images; // map from image name to image filename
* ...
* }
*
* Example 2:
*
* // MapKeyClass and target type of relationship can be defaulted
*
* @Entity
* public class Item {
* @Id int id;
* ...
* @ElementCollection
* Map<String, String> images;
* ...
* }
*
* Example 3:
*
* @Entity
* public class Company {
* @Id int id;
* ...
* @OneToMany(targetEntity=com.example.VicePresident.class)
* @MapKeyClass(com.example.Division.class)
* Map organization;
* }
*
* Example 4:
*
* // MapKeyClass and target type of relationship are defaulted
*
* @Entity
* public class Company {
* @Id int id;
* ...
* @OneToMany
* Map<Division, VicePresident> organization;
* }
*
*
* @see ElementCollection
* @see OneToMany
* @see ManyToMany
* @since Java Persistence 2.0
*/
@Target({ANNOTATION_TYPE, METHOD, FIELD})
@Retention(RUNTIME)
public @interface MapKeyClass
{
/**
* (Required) The type of the map key.
* @return The type
*/
Class value();
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy