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;
018import static javax.persistence.FetchType.LAZY;
019
020/**
021 * Defines a collection of instances of a basic type or embeddable class. Must be specified if the collection
022 * is to be mapped by means of a collection table.
023 * <p>
024 * <pre>
025 *    Example:
026 *
027 *    &#064;Entity public class Person {
028 *       &#064;Id protected String ssn;
029 *       protected String name;
030 *       ...
031 *       &#064;ElementCollection
032 *       protected Set&#060;String&#062; nickNames = new HashSet();
033 *         ...
034 *    }
035 * </pre>
036 *
037 * @since Java Persistence 2.0
038 */
039@Target({METHOD, FIELD})
040@Retention(RUNTIME)
041public @interface ElementCollection {
042
043  /**
044   * (Optional) The basic or embeddable class that is the element type of the collection. This element is
045   * optional only if the collection field or property is defined using Java generics, and must be specified
046   * otherwise. It defaults to the paramterized type of the collection when defined using generics.
047   *
048   * @return target class
049   */
050  Class targetClass() default void.class;
051
052  /**
053   * (Optional) Whether the collection should be lazily loaded or must be eagerly fetched. The EAGER
054   * strategy is a requirement on the persistence provider runtime that the collection elements must be
055   * eagerly fetched. The LAZY strategy is a hint to the persistence provider runtime.
056   *
057   * @return fetch type
058   */
059  FetchType fetch() default LAZY;
060}