2

I have been using JDBC (Java Database Connectivity) for a long time in my stand alone and web applications. Now my seniors asked me to use Hibernate framework instead JDBC for following reasons.

  • By using JDBC, resource leaks and data inconsistency happens as work is done by the developer.

  • Hard to implement MVC concept

  • No Encapsulation

  • Large programming overhead

  • Query is DBMS specific

Are these factors true ? Are there any more factors to support this ?

Why we should use Hibernate instead of JDBC ? Please help me with your ideas.

Thanks.

Du-Lacoste
  • 11,530
  • 2
  • 71
  • 51

1 Answers1

8

By using JDBC, resource leaks and data inconsistency happens as work is done by the developer.

False.

  1. Work is done by developer with hibernate also.
  2. If you mean that resource leaks happen because of repetitive code for manual Connection/(Prepared)Statement/ResultSet handling, there are lots of JDBC template frameworks that do this for you.
  3. Data inconsistency can happen with Hibernate also if you don't use it properly. For example, you instructed Hibernate to remove something from the database, but it ignored it because persist operation is cascaded to the removed entity. And now you have an inconsistent state in the db.

Hard to implement MVC concept

Partially true. Entities really help writing model part of MVC much easier.

No Encapsulation

Partially true. Indeed, mapping information can be specified in the entities only and are later automatically and (more or less) transparently reused in all use cases involving the entities.

Large programming overhead

Absolutely true. Basically, ORM solutions are frameworks that you would sooner or later end up writing by yourself when the persistence layer becomes too complex in your application. In my experience, even in moderately sized applications, manually written persistence frameworks are the most complex parts of the application.

Query is DBMS specific

True. Although there is nothing wrong in using native queries in use cases when HQL is not suitable for the job.

Are there any more factors to support this?

Other questions on SO:

Pros and Cons of Hibernate

Weaknesses of Hibernate

Hibernate or JDBC

JDBC VS Hibernate

Use Hibernate or not?

There are also hundreds of blogs and forum topics on this subject, you will quickly find them with your preferred web search engine.

Community
  • 1
  • 1
Dragan Bozanovic
  • 23,102
  • 5
  • 43
  • 110