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