Java – Is Spring + Hibernate Preferred Over EJB 3?

enterprise-developmenthibernatejavapersistencespring

It is my perception that whenever new JEE projects start (where these technologies would be applicable), people prefer to use a combination of Spring + Hibernate instead of EJB 3.

It seems junior programmers are even advised to go for that instead of EJB.

Is this personal preference or are there pertinent reasons for it? (e.g. personal scars created by earlier EJB versions which caused mistrust in EJB or technology bloat versus performance reasons or learning curve)?

Best Answer

The EJB 3+ frameworks are actually pretty good as they came along with JPA as an answer for annotation configured Persistence frameworks, as well as CDI which allows for annotation configured dependency injection. You also add on top of that Weld. Spring on the other hand is just now catching up in the game with configuration through annotation.

With that being said the historical backlack against EJB1 and 2 should not be discounted. They didn't just fail to solve the problems with writing enterprise applications, they spectacularly failed. It was a complete failure on the part of the designers to get a pulse on the true problems facing enterprise and web application developers and in turn deliver solutions that they actually needed.

Add on top of that the mistrust that there are some serious shakeups and instabilities with the current direction of Java at this time and lack of faith in the current stewards and owners of old Sun JVM, in Oracle. Many people do not have faith that Oracle will improve upon Java and lead the direction and there is also fear that the Apache Software Foundation may just throw in the towel. More and more people are looking to OpenJDK for the future of Java but it just isn't where it needs to be for Enterprise adoption.

Some see all of this as the smell of death as enterprise applications are the leading reasons why Java has historically been the #1 programming language in the world for as long as it has. This is why Microsoft has been gaining so much ground against Java with .NET technologies.

The non enterprise based Java application developers are turning more and more towards OpenJDK and other open source frameworks to help build their solutions and some are never looking back. One could say it is a case of too little too late on getting JEE back in the forefront of legitimacy, even though technically JEE can and does stand toe to toe with your comparable Spring application.