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