Hibernate Annotations Introduction

Hibernate » on Aug 28, 2011 { 6 Comments } By Sivateja

Gun short point :-  Annotations are replacement for XML

Let us see few points regarding annotations in hibernate

  • Annotations are introduced in java along with JDK 1.5, annotations are used to provide META data to the classes, variables, methods of java
  • Annotations are given by SUN as replacement to the use of xml files in java
  • In hibernate annotations are given to replace hibernate mapping [ xml ] files
  • While working with annotations in hibernate, we do not require any mapping files, but hibernate xml configuration file is must
  • hibernate borrowed annotations from java persistence API but hibernate it self doesn’t contain its own annotations
  • Every annotations is internally an Interface, but the key words starts with @ symbol


public @interface Java4s
    // code.....
  • For working with annotations, our java version must be 1.5 or higher and hibernate version must be hibernate 3.3 or higher, actually up to now we have been used hibernate 2.2 in our previous tutorials, get ready to download the higher version 🙂
  • At j2se level, sun has provided very limited set of annotations like @Override and @Deprecated …etc…
  • Sun has provided the annotations related to j2se level under java.lang.annotations.* package
  • Most of the annotations related to j2ee level are given by sun and their implementations are given by the vendors
  • In hibernate, the annotations supported are given by sun under javax.persistence package and hibernate has provided implementations for annotations given in that package

The basic annotations we are using while creating hibernate pojo classes are…

  • @Entity
  • @Table
  • @Id
  • @Column

Actually @Entity, @Table are class level annotations, and @Id, @Column are the field level annotations, no worries you will be able to understand while seeing the first example 🙂

  • in hibernate, if we are annotations in the pojo class then hibernate mapping file is not required, it means annotations are reducing the use of xml files in the hibernate

Though we are using annotations in our pojo class with mapping xml also, then hibernate will give first preference to xml only not for annotations,  actually this concept is same in struts, hibernate, spring too

And that’s it friends,  now you are ready to work with annotations in hibernate 😉


You Might Also Like

  ::. About the Author .::

Sivateja Kandula - Java/J2EE Full Stack Developer
Founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog, Love Java and UI frameworks.
You can sign-up for the Email Newsletter for your daily dose of Java tutorials.


6 Responses to “Hibernate Annotations Introduction”
  1. Raichand Ray says:

    Dear sir,
    Please post a Hibernate4 annotation,Primefaces5,Mysql,Maven CRUD Tutorial involving calendar component of Primeface5.

  2. ajay tiwari says:

    sir, i want to set the id like emp1,emp2,emp3,how can do it.
    please help me

  3. jogesh says:

    can we replace configuration file with annotations?

  4. rakesh says:

    in hibernate, if we are annotations in the pojo class then hibernate mapping file is not required, it means annotations are reducing the use of xml files in the hibernate
    i think sentanced should be modified in fisrt line

  5. Nazar says:

    Hi Sir,

    I would like to know what is the usage of allocationSize=50

    @SequenceGenerator(allocationSize=50, name = "USERS_SEQ", sequenceName = "SEQUENCE")

  6. Prem Kumar says:

    All the explanation has been explained very well manner, i really appreciate you for this content,

    I have question to ask how to manage session in hibernate , could you please add this tutorial by taking
    screen-shot ,



By posting your answer, you agree to our comments policy.
Most Recent Posts from Top Categories
Spring Boot Hibernate Spring
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2024 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.