Introduction

Hibernate Annotations

It is possible to run hibernate applications without using mapping file, but, we have to use Annotations.

To provide mapping details in Hibernate applications we have to use the following annotations provided by JPA in the form of “javax.persistence” package.

1. @Entity

It is a class level annotation, it can be used to declare a class as an Entity class.

2. @Table(name=”–“)

This annotation is a class level annotation, it can be used to configure table name for the entity class. Where “name” member is able to provide the respective table name.

3. @Id

This annotation is Field/Method[getXXX()] level annotation, it can be used to declare a property as ID property.

4. @Column(name=”–“)

This annotation is Field/Method [getXXX()] level annotation, it can be used to provide a database table column name in order to provide mapping .

In Hibernate Applications, to use annotations we have to use the following steps.

  • Remove mapping file and provide annotations ion POJO class.
  • In Configuration File, provide tag with “class” attribute in place of “resource” attribute. “class” attribute will take fully qualified name of the respective POJO class.
  • In Client Application, Create Either AnnotationConfiguration object or Configuration object to process Annotations.

Note

AnnotationConfiguration is deprecated class, so it is better to use Configuration class object to process annotations.

Introduction
Scroll to top