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