Let’s put Hibernate to sleep ?
Don’t get me wrong, Hibernate is a great tool written by very smart people, but I keep wondering how this technology has become so popular.
Maybe it’s just me, but for the past 3 years now I have not come across one single developer that grasps half of the concepts needed to understand how Hibernate works. They use it and don’t understand it.
This is a trend I have been witnessing more and more. Developers pick a technology because it is the hype of the moment, start to use it, get a hard time to get it to do what they want, but keep using it and advocate it. Probably because they don’t want to admit to the world they don’t understand it.
This is in my opinion what makes Hibernate (and the like) so popular.
To illustrate my point, we were just contracted by one of our customers to take over the maintenance of a codebase written by another company.
I will make no comment on the code itself, since I tend not to judge code written by others since code is always written in a specific “context” and, in my opinion, can not be judged without knowing that context.
The main complaint of the customer was that the application was getting slow. He had to wait from 5 minutes to 15 minutes to get one specific screen to dispay (I am not exagerating).
So we started a code analysis and had the chance to witness exactly what I was mentioning above. All the code was written exactly as if practice existed in “theory”.
The application had a magnificent (ironic) data model with 50 tables (entirely generated by Hibernate). An object graph sometimes 5 or 6 level deep.
While looking at it, I could hear the developer say on day 1 : Wouaw, this is so cool … I can do getEmployee().getDepartment().getRegion().getXXXX().getYYY().add(new ZZZ()) .. and it all works ..
And then the nightmare begins : lazy loading, hibernate session (open session in view issues), object identity, HQL, slow queries, etc ..
And so the developer (which never abandons) tries to “understand” by finding workarounds, tricks, breaks his architecture and does everything that is needed to make this nightmare work.
And so in day 15 (or 200 depending on the company you work for) : the code works (or seems to work) and nobody can touch it anymore because nobody understands it (except of course the main developer).
In our case, in production with real data (1.000.000 records or so – which is not even that big) the application is “curiously” verrrrrry slow ..
Just turning on the “show sql” in hibernate generated 3 Mb logs on every click …
The conclusion here is that, in my opinion, it is not a good idea to try to “hide” your database behind a “magic” object model. Even if Hibernate does its best to achieve just that, I think the challenge is not worth it .. The database will always pop back on you .. So embrace it ..
So we decided to remove the Hibernate layer and replaced it with IBatis. Hopefully the code was well structured and we were able to replace the Hibernate DAO layer by and equivalent (somewhat adapted) IBatis layer but not touching the above service layers.
When we choose a technology, we usually expect the following :
- It should pass the 10 minute test
- The learning curve should not be too steep
- It should serve a specific purpose and serve it well
- The technology should be understandable by a junior developer after 30 min introduction
Pierre


