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;
018
019/**
020 * Is used to specify the mapped column for a persistent property or field.
021 * If no <code>Column</code> annotation is specified, the default values apply.
022 * <p>
023 * <blockquote><pre>
024 *    Example 1:
025 * <p>
026 *    &#064;Column(name="DESC", nullable=false, length=512)
027 *    public String getDescription() { return description; }
028 * <p>
029 *    Example 2:
030 * <p>
031 *    &#064;Column(name="DESC",
032 *            columnDefinition="CLOB NOT NULL",
033 *            table="EMP_DETAIL")
034 *    &#064;Lob
035 *    public String getDescription() { return description; }
036 * <p>
037 *    Example 3:
038 * <p>
039 *    &#064;Column(name="ORDER_COST", updatable=false, precision=12, scale=2)
040 *    public BigDecimal getCost() { return cost; }
041 * <p>
042 * </pre></blockquote>
043 *
044 * @since Java Persistence 1.0
045 */
046@Target({METHOD, FIELD})
047@Retention(RUNTIME)
048public @interface Column {
049
050  /**
051   * (Optional) The name of the column. Defaults to
052   * the property or field name.
053   */
054  String name() default "";
055
056  /**
057   * (Optional) Whether the column is a unique key.  This is a
058   * shortcut for the <code>UniqueConstraint</code> annotation at the table
059   * level and is useful for when the unique key constraint
060   * corresponds to only a single column. This constraint applies
061   * in addition to any constraint entailed by primary key mapping and
062   * to constraints specified at the table level.
063   */
064  boolean unique() default false;
065
066  /**
067   * (Optional) Whether the database column is nullable.
068   */
069  boolean nullable() default true;
070
071  /**
072   * (Optional) Whether the column is included in SQL INSERT
073   * statements generated by the persistence provider.
074   */
075  boolean insertable() default true;
076
077  /**
078   * (Optional) Whether the column is included in SQL UPDATE
079   * statements generated by the persistence provider.
080   */
081  boolean updatable() default true;
082
083  /**
084   * (Optional) The SQL fragment that is used when
085   * generating the DDL for the column.
086   * <p> Defaults to the generated SQL to create a
087   * column of the inferred type.
088   */
089  String columnDefinition() default "";
090
091  /**
092   * (Optional) The name of the table that contains the column.
093   * If absent the column is assumed to be in the primary table.
094   */
095  String table() default "";
096
097  /**
098   * (Optional) The column length. (Applies only if a
099   * string-valued column is used.)
100   */
101  int length() default 255;
102
103  /**
104   * (Optional) The precision for a decimal (exact numeric)
105   * column. (Applies only if a decimal column is used.)
106   * Value must be set by developer if used when generating
107   * the DDL for the column.
108   */
109  int precision() default 0;
110
111  /**
112   * (Optional) The scale for a decimal (exact numeric) column.
113   * (Applies only if a decimal column is used.)
114   */
115  int scale() default 0;
116}