Tuesday, February 10, 2009

Why to use Hibernate for persistence layer

Instead of working directly with JDBC, Hibernate can be selected for ORM tool for your application's persistence needs.

When your application becomes larger and your requirements are not met by using JDBC, Hibernate comes to play.

Although there are many other benefits of using Hibernate, main sophisticated properties that a JDBC programmer encounters when working for the first time with Hibernate can be stated as follows:

Lazy loading : Most of the objects contain another objects in itself.

Consider, you have got a CreditCardApplication object which contains ApplicationRequestOwnerData and AdditionalInfo objects.

Assume that, you are retrieving a CreditCardApplication object, but you are not interested in the details of the ApplicationRequestOwnerData and AdditionalInfo objects in itself.

If it is unnecessary to fetch the whole object with its related objects, then lazy-loading brings a great effectiveness for your application.

Lazy-loading enables you to retrieve data as it is required.

Eager fetching : In opposite to lazy-loading, sometimes it is required to retrieve the whole object at a time. This decreases the cost of round trips.

Cascading : Support for cascading is another main benefit that you can design in your related hbm.xml file or annotations.

Generally speaking, using an ORM tool for persistence layer helps you to write less code in a shorter time period, if you use it effectively in your application.


hibernate.org is a great resource for new starters.

No comments:

Post a Comment