It is officially may be called epidemic at this stage. There is no statistics available but in my experience Hibernate is used probably in 80-90% of the cases across Java based projects. What is the fascination?
The ORM concept is not new and there were few attempts to implement it from early Entity EJBs to the JPA specification which is part of the J2EE framework now. Hibernate probably was the first more or less performing ORM library. It also was opensource which is usually quite appealing to the majority of the development community. As a result, it is more a religion now, i.e. if you start the new project consider to use Hibernate to interact with the database. No questions asked.
Crowd loves buzzwords. It is easier to sell yourself on the jobs market if you CV has couple of the modern fashionable buzzwords. I does not matter that majority of the management do not understand what it is used for and what are its strengths and weaknesses, it is an iconic thing now which means that if it is used in the project, the project must be successful.
Is it there any truth in the above statement? Is the overuse of the Hibernate justified?
I have no doubt that concept of ORM is good and useful and Hibernate is very good implementation of this concept. But let me first bring the following analogy.
Let's say we need quickly carry multiple bags from point A to point B which situated roughly 5 km from point A. Bags are small about 10 kg in weight and they appear in point A at the rate of 1 bag every 5 minutes. The task is as quickly as possible move them to the point B minimizing delays, i.e. do not allow bags gather in point A (minimize waiting).
In order to fulfill the task i have two vehicles: for example Yaris and large MAN lorry equipped with self lading and unloading gear. What options do i have? I can carry bags myself. But at my pace it is probably not feasible solution. So, there are two options left. Lorry is obviously great when talking about the carrying the weights. But should i move small objects with it? Probably no. It is both inefficient, i.e. would incur huge overhead and slow. So, Yaris in this case will be probably the better choice. It is not so efficient but the weight is not huge and it will be quicker because it is lighter.
Yes, my lovely lorry can do all job loading and unloading the stuff but i have to tune it up to do it. I will definitely need to load and unload bags to and from my Yaris myself and may be i would require some DIY to organize booth so it will efficiently stores my bags. But it will be quick with the minimum overhead.
My point is although OM concept is good it is not necessarily applicable to all possible scenarios.
In past number of years i came across number of projects where decision was made to use Hibernate without realization of why would the project needs it.
As a result in each of these situations projects were close to disaster due to performance issues.
Every layer of abstraction is coming with the price tag. It could be worth using it but bear in mind the performance will suffer.
The other important misunderstanding among developers is that Hibernate magically efficiently interacts with the database and you do not need to worry about it anymore. It is not true. Hibernate produces uniform SQL statements behind the scene that might be ok in the simple situations. However, in complicated cases it produces poor statements that inefficient and do not use all available tools that particular RDBMS can provide.
Another thing should be taken into account when you decide to use Hibernate is to plan you caching and commit strategies well before you start coding. They both might have devastating effect to the performance if applied incorrectly.
But the bottom line is think twice before using Hibernate in your project. Think twice.
No comments:
Post a Comment