Hi all,
in this article I will introduce you, young and bold Java programmer, to the Fantastic Hibernate 3 dream.
This article is worth to read, because give you a very fast track to Hibernate; I (Giovanni Giorgi) have used it for the past five years, when only the good 2.x series was out of there.
Then I have the lucky of training two teams on two different and big projects, with a “zero time” to teach them hibernate.
So I decided to put here my advices, hints, tips and tricks, for the rest of the guys around the World.
The goal of Hibernate “is to relieve the developer from 95 percent of common data persistence related programming tasks”.
Hibernate is an automatic tool to map in an efficient way objects to database
Hibernate is also an integration tool, because it is able to adapt a pre-existing database model to a brand new object model, providing an object-oriented view of a relational database. To cook them all, a set of “database” dialects are used to adapt tightly to the strength of the underlying database.
But you will soon like the hibernate-way :-)
You can think of DataAccessObjects (DAO) as “machine language”.
You have two options: you can write them by hand, or you can use a C compiler to do it (Hibernate is like an interpreter to mimic DAO-like access).
Hibernate is fast, efficient and can be tuned to be also fastest then a DAO.
You can believe me: you will not be able to be fastest then Hibernate (it is like to try to run faster then a Ferrari GTO using only your feet).
Only when you plan to do a sequential scan of a big table (for example for a batch work) you will come into trouble. But in any other context, Hibernate will outperform your DAOs.
Take a look to the documentation, mostly the good hibernate_reference.pdf.
I suggest you this order:
- Take a look to the first two chapters (Introduction and Architecture)
- Take a deep reading of Chapter 5 (Basic O/R Mapping) and Chapter 6, Collection Mapping
- The Chapter 14 HQL: The Hibernate Query Language, will be used soon by you, so keep an eye on it.
- Hibernate can generate for you SQL, in a very precise way. Take a look to Chapter 20.
- Finally take a look at the missed chapters.
The Hibernate manual is very well written, and you will not need any other guide to get started.
Let’s take a look to the following core concepts:
- You must understand the reason of redefinition of hashcode and equals, looking at § 4.3 “Implementing equals() and hashCode()”.
- You must understand why there is a first-level cache for the current session, and how lazy associations works.
Why lazy association are so important? - For simplicity and easy of use, I suggest you to start without a second level cache adding it only in a second step. Second level cache is a boost, but can also generate side-effects.
Last hint: do not expose Hibernate objects to the front end (like to Struts Action).
Use old plain vanilla data transfer beans (DTB) to communicate with front end layers.This approach is necessary, for avoiding troubles in the future.
If you have querstions, feel free to leave down a comment and I will reply you.
Resources
Related posts:
- Introduction to Bug Tracking tools At Gioorgi.com we will start a series of articles about bug tracking. As usual, our posts will be short, tight...
- Postgres Performance Tuning After a bit of work, I have managed to optimize the performance of my Postgresql Server. I have spent a...
- Designing Interfaces with Balsamiq In the last seven months I have the need of sketching a bunch of interfaces, but I cannot find a...
- Percorso Formativo: Finance Programma suggerito del percorso formativo “Finance” Object Oriented Programming (OOP) & Java Intro OOP: Hollywood Principle, “don’t call us, we’ll...
- Open Source for the Infrastructure At Gioorgi.com, after working with a lot with software for over twenty years, we have envisioned a clear idea about...


2 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.
Continuing the Discussion