KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > persistence > Column


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package javax.persistence;
24
25 import java.lang.annotation.Target JavaDoc;
26 import java.lang.annotation.Retention JavaDoc;
27 import static java.lang.annotation.ElementType.METHOD JavaDoc;
28 import static java.lang.annotation.ElementType.FIELD JavaDoc;
29 import static java.lang.annotation.RetentionPolicy.RUNTIME JavaDoc;
30
31 /**
32  * Is used to specify a mapped column for a persistent property or field.
33  * If no Column annotation is specified, the default values are applied.
34  * <p> Examples:
35  *
36  * <blockquote><pre>
37  * Example 1:
38  * &#064;Column(name="DESC", nullable=false, length=512)
39  * public String getDescription() { return description; }
40  *
41  * Example 2:
42  * &#064;Column(name="DESC",
43  * columnDefinition="CLOB NOT NULL",
44  * table="EMP_DETAIL")
45  * &#064;Lob
46  * public String getDescription() { return description; }
47  *
48  * Example 3:
49  * &#064;Column(name="ORDER_COST", updatable=false, precision=12, scale=2)
50  * public BigDecimal getCost() { return cost; }
51  *
52  * </pre></blockquote>
53  *
54  *
55  * @since Java Persistence 1.0
56  */

57 @Target JavaDoc({METHOD, FIELD})
58 @Retention JavaDoc(RUNTIME)
59 public @interface Column {
60
61     /**
62      * (Optional) The name of the column. Defaults to
63      * the property or field name.
64      */

65     String JavaDoc name() default "";
66
67     /**
68      * (Optional) Whether the property is a unique key. This is a
69      * shortcut for the UniqueConstraint annotation at the table
70      * level and is useful for when the unique key constraint is
71      * only a single field. This constraint applies in addition
72      * to any constraint entailed by primary key mapping and
73      * to constraints specified at the table level.
74      */

75     boolean unique() default false;
76
77     /**
78      * (Optional) Whether the database column is nullable.
79      */

80     boolean nullable() default true;
81
82     /**
83      * (Optional) Whether the column is included in SQL INSERT
84      * statements generated by the persistence provider.
85      */

86     boolean insertable() default true;
87
88     /**
89      * (Optional) Whether the column is included in SQL UPDATE
90      * statements generated by the persistence provider.
91      */

92     boolean updatable() default true;
93
94     /**
95      * (Optional) The SQL fragment that is used when
96      * generating the DDL for the column.
97      * <p> Defaults to the generated SQL to create a
98      * column of the inferred type.
99      */

100     String JavaDoc columnDefinition() default "";
101
102     /**
103      * (Optional) The name of the table that contains the column.
104      * If absent the column is assumed to be in the primary table.
105      */

106     String JavaDoc table() default "";
107
108     /**
109      * (Optional) The column length. (Applies only if a
110      * string-valued column is used.)
111      */

112     int length() default 255;
113
114     /**
115      * (Optional) The precision for a decimal (exact numeric)
116      * column. (Applies only if a decimal column is used.)
117      * Value must be set by developer if used when generating
118      * the DDL for the column.
119      */

120     int precision() default 0;
121
122     /**
123      * (Optional) The scale for a decimal (exact numeric) column.
124      * (Applies only if a decimal column is used.)
125      */

126     int scale() default 0;
127 }
128
Popular Tags