Ted says:
If you’re like most Java developers, you heard the term “EJB” and immediately got a note of distaste in your mouth.
Yep, that’s right. The first thing that comes to my mind is…complexity. You never really write EJBs by hand because there is so much duplication and so much configuration. The fact that EJBs (for all practical purposes) require code generation tools (XDoclet, wizards, etc) is a bad sign. He continues:
You know that if you suggest EJB on your next Java project, you will be ridiculed and shamed and made to stand in the corner with the Dunce Cap on, even if it makes complete sense from a technical perspective.
I wouldn’t suggest EJB for the next project. In fact, I’m trying to imagine how it would ever make complete sense from a technical perspective. I cannot think of any reason to advocate EJB.
The paragraph then suggests:
Companies are choosing instead to build their own transactional-oriented client/server middleware infrastructure, just to avoid the “shame” of using EJB. Because, as we all know, you just can’t test EJB.
I don’t think shame has much (if anything) to do with it, nor do I even think testing is that big a deal. Hardly anybody builds transactional infrastructure, although I guess that depends on what you mean by “transactional infrastructure”.
It is damn easy to grab Spring, Tomcat, and a handful of other open source projects to completely replace EJB. Not even a day’s effort. Hell, I recently put together a server-side app using Tomcat and Guice, and the whole “transactional infrastructure” consisted of little more than some ThreadLocal helper classes, a bit of AOP, and a servlet filter. Shame on me for spending a day to build my own infrastructure and be free from EJB for the next several years of maintenance on this project!
I submit to you that my Guice + Servlet project is far easier for humans to comprehend and maintain than any EJB app.
No Shame Here
We do not avoid EJB for “shame”. We avoid EJB because we know how much of a pain EJB is, and we know that thanks to products like Terracotta, for instance, we can duplicate EJB’s feats with far less pain.
EJB is painful because it suffers from accidental complexity. The programming model encourages duplication, and generally forces us to complicate our build procedures by incorporating code generation steps and/or “wizards”. At runtime, it is painful because it promotes a monolithic, gigantic EAR file that makes scaling out to clusters all that much harder. EJB is painful because it locks you in to a particular app server for all but the most trivial apps. It is painful because error messages are so cryptic. It is painful because of classpath woes. It is painful due to slow deployment, and OutOfMemoryErrors when you hot-deploy one to many times.
I feel no shame by advising my friends and customers: avoid EJB. There are better, simpler solutions, free solutions.
On Second Thought…
Maybe I would feel shame if I advised you to use EJB. I guess Ted’s right. I avoid EJB to avoid the shame.