Monday, April 18, 2011

Hibernate Versus JDBC

Long back I worked on a project in Java, Centralized Management System, to  manage multiple networking devices.  At that time  I remember having a  big debate on whether to use Hibernate for Java Object persistence or use JDBC directly.  We have finally decided to use Hibernate at that time.

I happened to come across this link which talks about 'when to use Hibernate' and also provides advantages and disadvantages of using hibernate.  I felt that it captures many points. Hence I thought of sharing this.

Please find it here :

One point  to consider by developers when using  Hibernate:
  • Different parts of application require different fields from a database table or from a set of related tables to be persistent.  Don't try to put all possible fields from database in one single java object class. Some database fields are more often required for your application than some other fields.  In those cases, you are better off using multiple persistent classes - for frequently used fields and for rarely used fields.  If you go with one single java persistent class, then you may be using more heap memory than necessary.   You know your application. Decide on the number of java persistent classes based on 'type of data',  'how often they are required' for applications etc.. For example, some data which is needed for auditing, which is once-in-a-while activity, may require separate java persistent class so that this object can be instantiated and removed on demand basis.  
Features I like in Hibernate (JPA):

  • It separates out the database organization with the business logic.  Due to Object-Relational mapping,  business logic always deals with the java class.  Mapping of java class members with the fields in database tables is defined in the XML file.  Any change in the database organization requires change only in the XML file.  
  • Change in the database server from vendor to another during field upgrade or during development has no or very less impact.
  • Automatic Version  & Time stamping feature of Hibernate ensures that there is no unintentional update of database by one thread using older data.
Above link has lot more information on the benefits. 

No comments: