Java Persistence with Hibernate Part 2 – Getting Started
In Java Persistence with Hibernate Part 1 I’ve discussed the need for object/relational persistence and some things that Hibernate aims to answer.
Hibernate has several modules which answer specific problems. The two most important modules to learn are Hibernate Core and Hibernate Annotations.
Hibernate Core
Hibernate Core for Java generates SQL for you, relieves you from manual JDBC result set handling and object conversion, and keeps your application portable to all SQL databases. Hibernate offers sophisticated query options, you can write plain SQL, object-oriented HQL (Hibernate Query Language), or create programatic Criteria and Example queries. – from hibernate.org
Hibernate Annotations
Hibernate, like all other object/relational mapping tools, requires metadata that governs the transformation of data from one representation to the other (and vice versa). As an option, you can now use JDK 5.0 annotations for object/relational mapping with Hibernate 3.2. You can use annotations in addition to or as a replacement of XML mapping metadata. – from hibernate.org
To be able to use the power of Hibernate we only need Hibernate Core. But since Hibernate Core requires a lot of XML configurations, Hibernate Annotations is used to make development simpler and faster. To better understand this let’s create a simple Hibernate application.
Getting Started
First we need to prepare all the libraries for creating a Hibernate application. This could be easily done if you know build tools like Maven or Ant but I decided not to use them because it’s not a requirement and maybe some of you are not familiar with those tools.
-
Download Hibernate Core
Extract the zip file and you will get hibernate3.jar. Image - Inside the lib folder there is a required folder and inside that you will find antlr-2.7.6.jar, commons-collections-3.1.jar, dom4j-1.6.1.jar, javassist-3.9.0.GA.jar and jta-1.1.jar. We will use a different version of sl4j. Image
- Download sl4j-1.5.6.zip and extract. We will need slf4j-api-1.5.6 and slf4j-simple-1.5.6
- Lastly we will need the JDBC driver for the database that we would be using, in this case MySQL 5.0. You may use other databases if you want just be sure know how to use them and configure them for database access from Java. Download the MySQL Connector/J 5.0. We need mysql-connector-java-5.0.8-bin.
Java Persistence with Hibernate Part 1 o0o Java Persistence with Hibernate Part 3 – Create the Database and Persistent Class

Recent Comments