Main Tutorials

Why i choose Hibernate for my project?

Currently my company is using IBATIS and pure SQLs as database persistence mechanism. I like SQL query very much, especially in tuning, but i do not like to write all SQL statement in Java application, it’s easy to hit typo error and what a stupid and tedious job?

Finally my company has a new project come in, and this is the right time to propose Hibernate as our new java database persistence mechanism tool. In order to persuade my boss to accept the Hibernate as the new project consideration, i have to highlight the benefits and advantages of Hibernate.

Why O/R mapping?

1. Productivity

It helps developers get rid of writing complex and tedious SQL statement, no more need of JDBC APIs for result set or data handling. It makes developers more concentrate on the business logic and increase the project’s productivity.

2. Maintainability

It helps reduce the lines of code, makes system more understandable and emphasizes more on business logic rather than persistence work (SQLs). More important, a system with less code is more easier to refactor.

3. Portability

It abstracts our application away from the underlying SQL database and sql dialect. Switching to other SQL database requires few changes in Hibernate configuration file (Write once / run-anywhere).

Boss : well, sound interesting tool to me. (actually , i do not know what are you talk about) is there any others O/R mapping tools or database persistence mechanism that did same thing like Hibernate?
Me : Yes,Boss, it does exits, however i need to tell you , why i choose Hibernate over the others.

Why choose Hibernate over the others?

Popular Open Source Persistence Frameworks in Java

1. Hibernatehttp://www.hibernate.org/
2. EJB3http://java.sun.com/products/ejb/index.jsp
3. Oracle Top Linkshttp://www.oracle.com/technology/products/ias/toplink/index.html
4. Cayennehttp://cayenne.apache.org/
5. Open JPAhttp://openjpa.apache.org/
6. IBATIShttp://ibatis.apache.org/javadownloads.cgi
7. JPOXhttp://www.jpox.org/

I do not want to compare every O/R or non O/R persistence mechanism individually, it may spent more than a year in research and hand-on practice comparative. Base on my personal humble opinion, I will choose Hibernate as the best O/R mapping persistence mechanism over the other tools.

Reason of choosing Hibernate

1. Productivity, Maintainability, Portability

Hibernate provides all above O/R benefits. (Productivity, Maintainability, Portability).

2. Free – Cost Effective

Hibernate is free and open source – Cost Effective

3. Learning curve is short

Since we all have working experience in using Hibernate, and Hibernate is totally object orientated concept, it will shorted our learning curve.

4. Code generation tool

Hibernate tools provided by community helps developer generate or develop hibernate application very fast and easy. (Eclipse’s Plugin & Code generation tools)

5. Popular

Hibernate is popular, when we goes wrong with Hibernate, we can easily find the answer from Google. In addition, there are many books, communities and forums on Hibernate.

Me: Hi Boss, hi, hi, are you listening?
Boss : …yes, yes, i get what you means.
Me :….(really?)
Boss : Since you listed out so many benefits, it’s open source and free, i will support you , just remember do not delay the delivery date.
Me : …… (free…delivery date…this is boss) Thanks Boss… you are Great!

Here’s one more advantage of using Hibernate that i didn’t inform my boss. May be i add it as number 6.

6) Market demand it

Java Market need Hibernate developer, demand of Hibernate developer is in decent growth and compare to the other tools. Hibernate working experience definitely add advantages for my next jump. Do you think i should inform my boss? 🙂

Reference

Hibernate tools (Eclipse Plugin & Code Generation)
http://www.hibernate.org/255.html
http://www.hibernate.org/hib_docs/tools/reference/en/html_single/

1. Is Hibernate the best choice?
http://java.dzone.com/news/hibernate-best-choice

2. Hibernate VS TopLink VS CMP
http://www.theserverside.com/discussions/thread.tss?thread_id=27037

3. Hibernate vs EJB 3.0 persistence
http://www.theserverside.com/discussions/thread.tss?thread_id=38800

4. Pros and Cons of Hibernate vs JDO vs EJB3 based persistence new J2EE app to build
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=78&t=000927

5. iBATIS vs Hibernate – What causes one to be choosen over the other?
http://www.javalobby.org/java/forums/t16496.html

6. Open Source Persistence Frameworks in Java
http://java-source.net/open-source/persistence

About Author

author image
Founder of Mkyong.com, love Java and open source stuff. Follow him on Twitter. If you like my tutorials, consider make a donation to these charities.

Comments

Subscribe
Notify of
24 Comments
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Igor
15 years ago

Well, as people say “A love is blind”. However I do admit that in some cases (very simple database structure, no strict performance requirements and a demand for multiple RDBMS support – ideally all of the above) this approach can be really useful. Unfortunately, sometimes the project looks simple at the beginning, but changes dramatically as it evolves. So I’m very skeptical about blind love in Hibernate or similar technologies.
There is another popular idea that ORM proponents seem to believe in: stored procedures are absolute evil. My personal experience cannot be an argument of course. However – do they think that all major RDBMS vendors are just so stupid to invest in ongoing improvement of SP support in their products?

Anas Mughal
15 years ago

No need to inform your boss. He knows already!

Hibernate has a steep learning curve. Part of the learning curve is the painful trouble shooting of the few few errors.

I am not a big fan of Hibernate.

Igor
15 years ago

Actually, I think that point 6 is the most (if not only) important argument. I met people who suggested using of Hibernate (or EJB) with the only reason – make their resume more sexy (after all they will have to look for a new job ASAP after the product reaches the production state – before the database will grow enough to put the “portable” application at its knees).

arun singh
4 years ago

thanks

Anatoli
9 years ago

Cool !! thats the way to go!!

prasad pallamreddy
10 years ago

sir i know the hibernate is best in market for orm tools ,but i need to know about drawbacks of hibernate.

Marcos
10 years ago

Hello Mkyong,

What do you think about using hibernate over a existing database with years of usage, lots of relationship tables +- 200 into 3 different schemas.

This database is basically used with PHP frontends.

There is not foreign key constraints, all happens through indexes. It is a MySQL 5 InnoDB.

Thanks and Regards,

Marcos Garcia.

Sridhar Goranti
11 years ago

Hello yong,thanks for the post. It is very useful for the beginners.

Mudassir Shahzad
11 years ago

Hello yong, thanks for the post. I didn’t hibernate was open source 😛
By the way, very nice article.
Its now in my bookmarks 🙂

Santiago Arispe
11 years ago

Hi.

someone can say me where get informatio, about How to add Hibernate support to java app without use IDE??
thanks..

xcalibur
11 years ago

i beleive when thing are going complex hibernate sucks. it was a tool for 200x ‘s. Time is changed, never think about hibernate.

vivek
11 years ago

My 2 cents.
I personally belive this dynamic SQL stuff that ORM tools promote, don’t really scale.
At the end of the day when you want enterprise scalability, and performance, you have to write stored procs, simply no other way.

Nowdays, I almost write all my apps, having all data centric logic in the stored proc and use java just as a workflow engine, in my opinion this solution – works.

Also no org changes database engines anymore on the fly, they have multi year support agreements with the vendors.

sathish
13 years ago

JPOX is now replaced by DataNucleus. JPOX is also no longer supported. You should upgrade to DataNucleus. http://www.datanucleus.org/

gagsy
13 years ago

Really useful and Informative tutorial.
thnx

software development company
14 years ago

I have never used hybernate befor but from what you are saying

1)Hibernate provides all above O/R benefits. (Productivity, Maintainability, Portability).

2) Hibernate is free and open source – Cost Effective

3) Hibernate learning curve is short. Since we all have working experience in using Hibernate, and Hibernate is totally object orientated concept, it will shorted our learning curve.

4) Hibernate tools provided by community helps developer generate or develop hibernate application very fast and easy. (Eclipse’s Plugin & Code generation tools)

5) Hibernate is popular, when we goes wrong with Hibernate, we can easily find the answer from Google. In addition, there are many books, communities and forums on Hibernate.

It is a good idea to use it from now on thanks for posting this

sri
14 years ago

It’s for making things complex to make it simple…..
I too agree with point 6. I get jobs.
Why a company changes the database after completion of development.Even if database is changed complex db operations need a change… we can find answer in google for DAO JDBC also.

Any company needs a robust solution, but what does your company do with the popularity of hibernate?

radgid
15 years ago

“Switching to other SQL database requires few changes in Hibernate configuration file (Write once / run-anywhere)”

Do you know about any serious company that pays for the development of the system with the data stored in E.g. Oracle RDBMS and then after implementation decides to switch to another database? Wake up 🙂

Javier
15 years ago

I totally agree with point 6, for personal experience, work with Hibernate was a really good choice since I get a better job after one project use it.

HowToDoInJava
9 years ago
Reply to  mkyong

Hey mkyong, I am also author at one of relatively less known java blog (howtodoinjava.com) and I wonder how you get time to write all these tutorials.. any suggestion??