Basic annotation in Hibernate/JPA

Hello guys,

Welcome back to Hibernate series. Today we are are going to discuss some basic annotation use in hibernate. Its really imperative to know this annotation, if you want to move one step ahead from configuration to annotation. So let’s start the journey of annotation in POJO classes.

Most useful and valuable basic annotations are following:-

1). @Entity
2). @Table
3). @Column
4). @Id
5). @GeneratedValue
1.) @Entity:- The @Entity annotation is used to mark this class as an Entity bean. So that the class should at least have a default constructor and setter and getter for all the fields or related fields. It is defined in javax.persistence.Entity package.

2). @Table:- The @Table annotation is used to define the table to persist the data. You can refer to use name attribute with the table annotation for specifying own table name like @Table(name=”Jellyfish”). If you are not using @Table column then hibernate will be defined by default table name same with the Entity or class name. The @Table is defined in javax.persistence.Table package
3). @Column:- The @Column annotation is used to specify the details of the column to which a field or property will be mapped. If the @Column annotation is not specified, the property name will be used as the column name by default. The @Column is defined in javax.persistence.Column package

4). @Id:- The @Id annotation is used to specify the identifier property of the class or entity bean. The @Id is defined in javax.persistence.Id package

5). @GeneratedValue:– The @GeneratedValue annotation is used to specify the primary key generation strategy to use. If the strategy is not specified by default AUTO will be used. There are many types available of generation type to inject in the @generatedValue annotation. The @GeneratedValue is defined in javax.persistence.GeneratedValue package


There is an example below to define how to use all annotations which are given upon:-

Thank you guys for giving me your valuable time. I will be back with the new amazing tutorial. till then bye and happy learning.