Hibernate Made Easy : 1 - Hibernate Introduction

Hi Everyone, in this blog post, I am writing about a sample program in hibernate. By definition hibernate is an object relational mapping library for java, providing a framework for mapping an object domain model to a traditional relational database (Wikipedia definition). In simpler terms, hibernate is used to map java objects to database tables.

Object Relational Mapping - Programming technique for converting data type between incompatible type systems in object oriented programming techniques. Here objects and variables in a class are converted to table and fields in database respectively.

Framework - An abstraction in which software providing generic functionality can be selectively changed by additional user written code.

Relational Database - Collection of data items organized as a set of formally described tables from which data can be accessed easily.

Hibernate is mainly used for mapping from java objects to database tables and from java data types to sql data types. It also provides querying and retrieval of data from database.

Why Hibernate?

Why we need hibernate even though we have jdbc, which performs all the functions that hibernate does ? The reason is simple because of the following advantages: 

  •  Hibernate saves a lot of time in coding and debugging. 
  • Setting up of hibernate is very easy compared to jdbc. 
  • Hibernate have layered architecture which enables to use the components according to your application needs.
  • Every database can be used with hibernate.
  • There are many caching framework available in hibernate, which will improve the performance of hibernate.
  • Hibernate supports relationships like one-to-one, one-to-many, many-to-many, many-to-one.
  • Hibernate supports inheritance, associations and collections.
Hibernate also have one disadvantage with respect to jdbc that it is slow in execution compared to jdbc and it is not suitable for batch processing.


Setting up of hibernate


To set up hibernate, we need to download the hibernate libraries from hibernate.org/downloads. The new version of hibernate libraries zip file will be available in a link called release bundles. I have downloaded hibernate-distribution-3.6.4.Final-dist.zip.


To start a hibernate project in eclipse, it is same as starting a java project except we have to import the hibernate libraries.

We have to import the following libraries from the zip while you have downlaoded :-

  • hibernate3.jar
  • javassist :- present in javaassist folder in bytecode.
  • hibernate jpa :- present in jpa folder in lib.
  • antir :- present in required folder in lib.
  • commons-collections :- present in required folder in lib.
  • dom4j :- present in required folder in lib.
  • jta :- present in required folder in lib.
  • slf4j :- present in required folder in lib.

The directory structure of hibernate libraries is as follows:
















I hope this blog post gave you a clear idea about hibernate, why we use hibernate and setting up of hibernate. In the coming posts, I will present some sample programs and more interesting technologies in hibernate. Please comment below if you have any doubts. 

Thank you for reading the post.

Comments

Popular posts from this blog

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

Anonymous classes in C++