Important annotations used in Hibernate

Hi everyone, in this blogpost, I am discussing about some of the important annotations used in Hibernate. Following are some of the important annotations: -
  1. @Entity - @Entity specifies that the class is marked as an entity bean.

  2. @Table -  @Table is used to specify the table for persisting data. The optional attributes of the table annotation is 'name' and 'schema' which specifies both the name and schema of the table respectively. Other attributes are 'unique constraints' which specifies the unique constraints that are to be placed on the table and 'catalog' which specifies the catalog of the table.

  3. @Id - @Id specifies the identifier property of the entity bean. It is like a primary key of the table. The mapped column for primary key of the entity is assumed to be primary key of the primary table. If no column annotation is specified, the primary key column is assumed to be the name of primary key property or field.

  4. @Column - @Column specifies the details of the column to which a field or a property will be matched. If @Column annotation is not specified, the default property name will be used as column name. @Column has the following attributes: 
  • name - Specifies the name of the column

  • length - Specifies the size of the column used to map a value 

  • nullable - Specifies that the column cannot be marked NOT NULL when schema is generated.

  • unique - Specifies the column should contain only unique values.
     5.  @GeneratedValue - @GeneratedValue specifies the primary key generation strategy. If no      strategy is specified, the default specification will be AUTO.

I believe this blogpost have given you the idea about basic annotations used in hibernate. Please comment below if you have any comments/suggestions. Also please check my upcoming posts to know more about hibernate.

Thank you for reading my post.

Comments

Post a Comment

Popular posts from this blog

Difference between "diff" and "sdiff" commands in Unix

Anonymous classes in C++