java jpa 注解_Spring JPA 注解 Column属性 详解

源码:

/*******************************************************************************

* Copyright (c) 2008 - 2013 Oracle Corporation. All rights reserved.

*

* This program and the accompanying materials are made available under the

* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0

* which accompanies this distribution.

* The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html

* and the Eclipse Distribution License is available at

* http://www.eclipse.org/org/documents/edl-v10.php.

*

* Contributors:

* Linda DeMichiel - Java Persistence 2.1

* Linda DeMichiel - Java Persistence 2.0

*

******************************************************************************/

package javax.persistence;

import java.lang.annotation.Target;

import java.lang.annotation.Retention;

import static java.lang.annotation.ElementType.METHOD;

import static java.lang.annotation.ElementType.FIELD;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**

* Specifies the mapped column for a persistent property or field.

* If no Column annotation is specified, the default values apply.

*

*

 
  

* Example 1:

*

* @Column(name="DESC", nullable=false, length=512)

* public String getDescription() { return description; }

*

* Example 2:

*

* @Column(name="DESC",

* columnDefinition="CLOB NOT NULL",

* table="EMP_DETAIL")

* @Lob

* public String getDescription() { return description; }

*

* Example 3:

*

* @Column(name="ORDER_COST", updatable=false, precision=12, scale=2)

* public BigDecimal getCost() { return cost; }

*

*

*

*

* @since Java Persistence 1.0

*/

@Target({METHOD, FIELD})

@Retention(RUNTIME)

public @interface Column {

/**

* (Optional) The name of the column. Defaults to

* the property or field name.

*/

String name() default "";

/**

* (Optional) Whether the column is a unique key. This is a

* shortcut for the UniqueConstraint annotation at the table

* level and is useful for when the unique key constraint

* corresponds to only a single column. This constraint applies

* in addition to any constraint entailed by primary key mapping and

* to constraints specified at the table level.

*/

boolean unique() default false;

/**

* (Optional) Whether the database column is nullable.

*/

boolean nullable() default true;

/**

* (Optional) Whether the column is included in SQL INSERT

* statements generated by the persistence provider.

*/

boolean insertable() default true;

/**

* (Optional) Whether the column is included in SQL UPDATE

* statements generated by the persistence provider.

*/

boolean updatable() default true;

/**

* (Optional) The SQL fragment that is used when

* generating the DDL for the column.

*

Defaults to the generated SQL to create a

* column of the inferred type.

*/

String columnDefinition() default "";

/**

* (Optional) The name of the table that contains the column.

* If absent the column is assumed to be in the primary table.

*/

String table() default "";

/**

* (Optional) The column length. (Applies only if a

* string-valued column is used.)

*/

int length() default 255;

/**

* (Optional) The precision for a decimal (exact numeric)

* column. (Applies only if a decimal column is used.)

* Value must be set by developer if used when generating

* the DDL for the column.

*/

int precision() default 0;

/**

* (Optional) The scale for a decimal (exact numeric) column.

* (Applies only if a decimal column is used.)

*/

int scale() default 0;

}

name

name属性定义了被标注字段在数据库表中所对应字段的名称;

unique

unique属性表示该字段是否为唯一标识,默认为false。如果表中有一个字段需要唯一标识,则既可以使用该标记,也可以使用@Table标记中的@UniqueConstraint。

nullable

nullable属性表示该字段是否可以为null值,默认为true。

insertable

insertable属性表示在使用“INSERT”脚本插入数据时,是否需要插入该字段的值。

updatable

updatable属性表示在使用“UPDATE”脚本插入数据时,是否需要更新该字段的值。insertable和updatable属性一般多用于只读的属性,例如主键和外键等。这些字段的值通常是自动生成的。

columnDefinition

columnDefinition属性表示创建表时,该字段创建的SQL语句,一般用于通过Entity生成表定义时使用。(也就是说,如果DB中表已经建好,该属性没有必要使用。)

table

table属性定义了包含当前字段的表名。

length

length属性表示字段的长度,当字段的类型为varchar时,该属性才有效,默认为255个字符。

precision和scale

precision属性和scale属性表示精度,当字段类型为double时,precision表示数值的总长度,scale表示小数点所占的位数。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值