1.2. Part 1 - The first Hibernate Application

1.2. Part 1 - The first Hibernate Application

First, we'll create a simple console-based Hibernate application. We use an Java database (HSQL DB), so we do not have to install any database server.

Let's assume we need a small database application that can store events we want to attend, and information about the hosts of these events.

The first thing we do, is set up our development directory and put all the Java libraries we need into it. Download the Hibernate distribution from the Hibernate website. Extract the package and place all required libraries found in /lib into into the /lib directory of your new development working directory. It should look like this:

.
+lib
  antlr.jar
  cglib.jar
  asm.jar
  asm-attrs.jars
  commons-collections.jar
  commons-logging.jar
  hibernate3.jar
  jta.jar
  dom4j.jar
  log4j.jar

This is the minimum set of required libraries (note that we also copied hibernate3.jar, the main archive) for Hibernate at the time of writing. The Hibernate release you are using might require more or less libraries. See the README.txt file in the lib/ directory of the Hibernate distribution for more information about required and optional third-party libraries. (Actually, Log4j is not required but preferred by many developers.)

Next we create a class that represents the event we want to store in database.