Hibernate Introduction



Short introduction

Hibernate is a solution for object relational mapping and a persistence management solution or persistent layer. This is probably not understandable for anybody learning Hibernate.

What you can imagine is probably that you have your application with some functions (business logic) and you want to save data in a database. When you use Java all the business logic normally works with objects of different class types. Your database tables are not at all objects.

Hibernate provides a solution to map database tables to a class. It copies one row of the database data to a class. In the other direction it supports to save objects to the database. In this process the object is transformed to one or more tables.

Saving data to a storage is called persistence. And the copying of tables to objects and vice versa is called object relational mapping.

Create a Java Project

Using Eclipse press the keys Ctrl+n (Strg+n) to create a new project. Select a Java project. We will call it FirstHibernateExample.

Prepare the project for Hibernate using MyEclipse

When you are using MyEclipse, right click on your project in the package explorer and choose Add Hibernate capabilities.

–>Select the Package Explorer in the Left Side of  the EclipseIDE and in that
–>Select FirstHibernateProgram
|
|___Select MyEclipse
|
|__Add Hibernate Capabilities

After that

Continue the wizard and create a new hibernate.cfg.xml in the src directory.

In the last step you can create a Hibernate SessionFactory. I prefer to create my own. You can find it below.
Prepare the project for Hibernate for anybody

When you do not use MyEclipse download Hibernate from the website http://www.hibernate.org/

Extract the file. Hibernate comes with a long list of libraries. You do not need all of them. There is a REAME file in the lib directory explaining what is required. Open your project properties, select ?Java Build Path?, click on ?Add External Jars? and add the libaries shown below to your project path.
—>xml-apis.jar
—>asm.jar
—>asm-attrs.jar
—>c3p0-0.9.0.jar
—>cglib-2.1.3.jar
—>commons-logging-1.0.4.jar
—>concurrent-1.3.2.jar
—>dom4j-1.6.1.jar
—>ehcache-1.1.jar
—>hibernate3.jar
—>jacc-1_0-fr.jar
—>jaxen-1.1-beta-7.jar
—>jdbc2_0-stdext.jar
—>jta.jar
—>log4j-1.2.11.jar
—>antlr-2.7.6rc1.jar

Share with SociBook.com

Random Posts

Post a Comment