Do Spring combined with Hibernate weigh less than EJB?

Lofi Dewanto in his blog asks if Spring framework used with Hibernate is still a lightweight or a heavyweight champion of Java frameworks?

I believe that not only this combo, but even each of them separately is pretty heavy as ANY framework. Only reusable loosely coupled components are lightweights.

Spring framework is advertised as a set of components that can be used separately, but you can also wire them together by adding two pounds of XML. The minute you do this, you fall into an XML trap. So if you use any single component of the Spring framework it ‘s lightweight. But as soon as it takes two to tango, and you are pulling a tiny roll of thin wire out of your pocket, it becomes heavyweight. Because wires (a.k.a. XML) tend to twist and create a mess.

Speaking of Hibernate, I ‘m not even sure WHY so many people are using it in the first place? I can understand if an enterprise architect is laying out a new design of a stack of business applications and wants to enforce to a firm-wide standard for data persistence. But if you are developing a typical CRUD application, especially when it comes to using already existing and not perfectly designed database, why even bother with Hibernate? Do you really hate or afraid of SQL?

Anyway, take an application built on the Spring framework components interconnected with thin wires, put on top of it Hibernate with the wires of different diameter, and maintainability of your application decreases while hard to find bugs are making themselves at home in your application.

During the last three to four years many people like bashing EJBs as an unnecessary complicated framework with lots of convoluted XML descriptors. Now EJB 3.0 with its annotations is trying to appeal to enterprise developers again. This won ‘t be easy, because bad memories last for years. But do not kid youself when you substitute EJB for Spring/Hibernate combo. Your life won ‘t be easier at all.

I do believe in standalone POJOs which know nothing about environment they are in (an IoC concept works fine), and know how to perform a specific function, i.e. send a message, manage transactions, create a pretty report based on provided SQL, model some financial process, find an optimal route, e.t.c. Just pass the required parameters to this black box, get the result back and do whatever you want with it. Stop wiring, just write the freaking code specific to your business application and forget about it when the new project start. Do not forget though about independent reusable components.

Spring is probably one of the best Java frameworks available today. It has only one drawback: it ‘s a framework.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s