Why Hibernate instead of direct JDBC ?


Hibernate is a powerful, high performance Object/Relational persistance and query service for both Java and .Net. Hibernate provides the bridge between the database and the application by storing application objects in the database for the developer, rather than requiring the developer to write and maintain mountains of code to store and retrieve objects.

Using a JDBC connection you’ll be unable to store objects directly to the database-you must convert the objects to a relational format. If we consider a domain class called Event, and if you want to persist a new instance of the Event class to the database, you must first convert the Event object to a SQL statement that can be executed on the underlying database. Similarly, when rows are returned from the database, you must convert each result row into an instance of Event.

When working with objects, you are generally using a number of connected objects. This is called as an object graph. An object graph represent an internally consistent view of application data. Internally consistence means that a change made to one object is reflected throughout the graph. The objects within a graph are typically connected using one-to-one or one-to-many associations.

Using direct JDBC for persistence presents distinct problems for each of the persistence operations: creation, updating, retrieval, and deletion.

Hibernate addresses all the shortcomings of the persistence techniques using direct JDBC and offers a number of additional features. Using Hibernate doesn’t require that your domain objects implement specific interface or use an application server. It supports collections, inheritance, and custom data types, as well as a rich query language.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s