Share on Google+Share on Google+

Hibernate Column

This tutorial explains the concept of column annotation in hibernate.

Hibernate Column

This tutorial explains the concept of column annotation in hibernate.

Hibernate column :

In Hibernate, column attribute plays an important role in mapping table. column annotation is defined in javax.persistence package. It is used to define a mapped column for a persistence field.

As we map table fields in our persistence class by using @column annotation and also we can specify other properties.

Syntax -

@Column(name="column_name" ,columnDefinition="CLOB NOT NULL" ,insertable=true/false ,length=N ,nullable=true/false ,precision=N ,scale=N ,table="" ,unique=true/false ,updatable=true/false)

Description of Optional Elements:

name: It is name of column that represent to table field. by default it takes field name or property.
Default value: ""

columnDefinition: It shows the SQL fragment that is used when generating the DDL for the column. By default it takes the generated SQL to create a column of the inferred type.
Default value: ""

insertable: It is used to check for the column is included in SQL INSERT statements which is generated by the persistence provider or not.
Default value: true

nullable: It is of Boolean type and checks the column name is either nullable or not.
Default value: true

length: It is optional and sets the column length only if you use string valued column.
Default value : 255

precision: It is optional applies only if a decimal column is used. Value is set by programmer if used when generating the DDL for column.
Default value: 0

scale: It is used for scaling for a decimal(exact numeric) column and is applied only if a decimal column is presented.
Default value : 0

table: It refer to the name of the table that contains the column. If it is not present then the column name is assumed to be in the primary table.
Default value: ""

unique: It checks whether the property is a unique key or not. It is useful for checking unique key constraint of single field.
Default value: false

updatable: It checks whether the column updatable or not
Default value: true


Posted on: July 4, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Discuss: Hibernate Column  

Post your Comment

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image