Indus IT - Tutorials

Struts2 Tutorial Hibernate Tutorial Spring Tutorial EJB Tutorial
 
J2EE/EE Tutorial Spring Batch Tutorial Integration Tutorial JMS/AQ Tutorial

Introduction

Hibernate Tutorial

Hibernate Session

Hibernate Annotations

Hibernate 2.x vs 3.x

Hibernate Migration

Tool Tips

Best Practices

Download

Hibernate Reference

 

Message Board

Resources

Send Tutorial/Tip

Hibernate 3 Tutorial

Previous   Next

Step1>Getting Ready

ORM is a way to map java objects for automatic persistence of objects into a database. The issues to be resolved by the ORM are: how mappings to tables are defined , how can we translate the inheritance in Java to database tables and how the queries can be defined in an object oriented way. The ORM tools are designed to increase productivity, make maintenance easier and allow for performance optimzations.

Hibernate is the leading ORM framework/tool. It provides Java based veiw of persistent data. It works with POJO(Plain Old Java Objects) to avoid any overheads. It supports object oriented concepts of encapsulation, inheritance and polymorphism. It allows for writing SQL queries to be written externally in the files and maintained separately, adding flexibility. Queries are written in Object oriented way using objects instead of tables, using HQL(Hibernate Query Language).

Before you get into developing an example application download the Hibernate using link on left. Also you can download the oracle xpress edition free by clicking on this text. The exact setup used in the tutorial is like this:

  • Oracle database express edition: version 10g XE
  • Hibernate Core: version 3.3.2
  • Hibernate Annotations: version 3.4.0
  • IDE used: Eclipse Java EE IDE for web developers(I suppose Any version is fine)
Tip Be very careful, in setting your class path. The incompatibilities in the jar files can make your life miserable, in todays open source based systems.

Especially be careful about the SLF4J files. SLF4J or Simple Logging Facade for Java is used by Hibernate libraries to do logging through Log4j tool. Where we have choices there we have to pay price sometimes. The combination and order of jar files is important. If you follow the order and include the following jars you should be fine other wise the inter-dependency of the jar files can be tricky. You do not need to have the ojdbc14.jar file in your class path if you are not using Oracle database. This jar contains the drivers for Oracle DB, you can replace this one with the jar file for the database you use.

Tip Try to download a jar file from internet if you cannot find it in the Hibernate download. Keep the version number in mind when downloading.

List of jar files needed for Hibernate development:
hibernate-distribution-3.3.2.GA/hibernate3.jar
hibernate-distribution-3.3.2.GA/lib/required/antlr-2.7.6.jar
hibernate-distribution-3.3.2.GA/lib/required/dom4j-1.6.1.jar
hibernate-distribution-3.3.2.GA/lib/required/javassist-3.9.0.GA.jar
hibernate-distribution-3.3.2.GA/lib/required/jta-1.1.jar
hibernate-annotations-3.4.0.GA/lib/dom4j.jar
hibernate-annotations-3.4.0.GA/lib/ejb3-persistence.jar
hibernate-annotations-3.4.0.GA/lib/hibernate-commons-annotations.jar
hibernate-annotations-3.4.0.GA/lib/hibernate-core.jar
hibernate-annotations-3.4.0.GA/hibernate-annotations.jar
ojdbc14.jar
slf4j-log4j12-1.4.2.jar
slf4j-api-1.5.8.jar
log4j-1.2.14.jar
commons-collections-3.1.jar

Hibernate Core is the core framework which handles all the base fucntionality provided by Hibernate ORM. Additionally the Hibernate Annotations component adds up the annotations(Java Annotations) based functionality into the Hibernate3.x version. The annotations component adds Java 5 and Hiibernate specific annotations to be used in Hibernate3 version. Regarding the last item, I guess everyone knows what IDE and Eclipse is, that is the Integratred Developement Environment which enables faster software development.

This tutorial will be a fast one, to let you start up Hibernate quickly, so that you can learn the details later.

Previous Next


Copyright (c) 2009 All rights reserved.