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.EAGER;
019
020/**
021 * The simplest type of mapping to a database column. The
022 * <code>Basic</code> annotation can be applied to a persistent
023 * property or instance variable of any of the following types: Java
024 * primitive types, wrappers of the primitive types, <code>String</code>,
025 * <code>java.math.BigInteger</code>,
026 * <code>java.math.BigDecimal</code>,
027 * <code>java.util.Date</code>,
028 * <code>java.util.Calendar</code>,
029 * <code>java.sql.Date</code>,
030 * <code>java.sql.Time</code>,
031 * <code>java.sql.Timestamp</code>, <code>byte[]</code>, <code>Byte[]</code>,
032 * <code>char[]</code>, <code>Character[]</code>, enums, and any other type that
033 * implements <code>java.io.Serializable</code>.
034 * <p>
035 * <p> The use of the <code>Basic</code> annotation is optional for
036 * persistent fields and properties of these types.  If the
037 * <code>Basic</code> annotation is not specified for such a field or
038 * property, the default values of the <code>Basic</code> annotation
039 * will apply.
040 * <p>
041 * <pre>
042 *    Example 1:
043 *
044 *    &#064;Basic
045 *    protected String name;
046 *
047 *    Example 2:
048 *
049 *    &#064;Basic(fetch=LAZY)
050 *    protected String getName() { return name; }
051 *
052 * </pre>
053 *
054 * @since Java Persistence 1.0
055 */
056@Target({METHOD, FIELD})
057@Retention(RUNTIME)
058public @interface Basic {
059
060  /**
061   * (Optional) Defines whether the value of the field or property should
062   * be lazily loaded or must be eagerly fetched. The <code>EAGER</code>
063   * strategy is a requirement on the persistence provider runtime
064   * that the value must be eagerly fetched.  The <code>LAZY</code>
065   * strategy is a hint to the persistence provider runtime.
066   * If not specified, defaults to <code>EAGER</code>.
067   */
068  FetchType fetch() default EAGER;
069
070  /**
071   * (Optional) Defines whether the value of the field or property may be null.
072   * This is a hint and is disregarded for primitive types; it may
073   * be used in schema generation.
074   * If not specified, defaults to <code>true</code>.
075   */
076  boolean optional() default true;
077}