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. Hibernate – http://www.hibernate.org/
2. EJB3 – http://java.sun.com/products/ejb/index.jsp
3. Oracle Top Links – http://www.oracle.com/technology/products/ias/toplink/index.html
4. Cayenne – http://cayenne.apache.org/
5. Open JPA – http://openjpa.apache.org/
6. IBATIS– http://ibatis.apache.org/javadownloads.cgi
7. JPOX – http://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
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?
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.
when we first learn about Hibernate, we will start thinking why we need hibernate? declare this and that, xml mapping , define relationship…. with single SQL statement i can did all of that, why we need it? Project delay will all count on your fault…..
well, this is because Hibernate totally changed the way we work before, that why we will feel uncomfortable….However when we go though the painful uncomfortable stage, we will all fall love in Hibernate’s development speed, maintainability and object oriented style ~
Actually i’m big fan of Hibernate , because Hibernate bring me few successful projects’ experience.
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).
when database grow to 100 or 200millions, or even more data, i do not think application level can solve this issue. (if you know any , please tell me). Solution always come to database partition and clustering.
I will still propose and suggest Hibernate as a database persistence mechanism for other projects, not only for my sexy resume, some of the Hibernate features provided , we really hard to find a reason to deny it. Especially when we facing some tight project deathline, Hibernate development speed definitely is my first choice.
thanks
Cool !! thats the way to go!!
sir i know the hibernate is best in market for orm tools ,but i need to know about drawbacks of hibernate.
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.
Hello yong,thanks for the post. It is very useful for the beginners.
Hello yong, thanks for the post. I didn’t hibernate was open source 😛
By the way, very nice article.
Its now in my bookmarks 🙂
Hi.
someone can say me where get informatio, about How to add Hibernate support to java app without use IDE??
thanks..
i beleive when thing are going complex hibernate sucks. it was a tool for 200x ‘s. Time is changed, never think about hibernate.
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.
JPOX is now replaced by DataNucleus. JPOX is also no longer supported. You should upgrade to DataNucleus. http://www.datanucleus.org/
Really useful and Informative tutorial.
thnx
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
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?
just try do not put any business logic inside database, client always want to change the database because of existing license or working partner issue.
ya sometime it’s make thing more complex because we always put our resume ahead of requirement.
“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 🙂
Ya, i agreed with your point, large company or end user company wont change their database system. However vendor or software house did change solution always, because it’s customize different solution for different end user company.
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.
hi Javier, i got a good job because of hibernate working experience as well ~
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??