Get all updates of Java4s
Follow Us: Email Newsletter

Hibernate Annotations Introduction

Hibernate » On Aug 28, 2011 { 4 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


  • 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 Author ♦

Full Stack( Java/J2EE & UI/UX ) Developer and founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog. Sign-up for the Email Newsletter for your daily dose of Java tutorials.


4 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


By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Useful Links Current & UpComing Tutorials
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

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