Chris Johnston

Web development and design with a little VFX thrown in for fun
  • Home
  • About Me
  • Contact Me
  • Projects
  • Resume

The Problem with EJBs

Published by Chris Johnston on September 18, 2006 08:33 pm under J2EE

I had someone post a question in the comments section of my last post on Behavior-Driven Development “asking about EJBs”:http://www.fuzzylizard.com/archives/2006/09/15/794/#comments. I thought I would answer it with a new post instead of just a comment. Where do I start?

First, I need to define the term EJBs. For me, EJB means either Session Bean (stateless or statefull) or Message-Driven Bean. It does not mean Entity Bean. Entity Beans are just wrong and will not be considered further. As far as I can tell, no one really uses them (yes, there are exceptions, but those people are just masochists).

What is the state of Session and Message-Driven Beans? Some people use them, others do not. I personally would advise against them. The vast majority of applications are not distributed, run in a single app server, and can be completely implemented in the web container.

The main problem with EJBS is that they are completely untestable. This is a huge problem. There is no way for me to run a simple JUnit test against a session bean from within an IDE such as NetBeans or Eclipse. In order to test an EJB, I need to build and deploy the entire application inside of the application server. I then need to figure out some artificial way of entering into the app server and executing a method or two on a single bean. Not a fun way of doing development.

In order to do any kind of real development with EJBs you need to abstract all of you business logic out of the bean and place it into POJO that the bean then calls. In order to do this, you need to introduce another interface to ensure that the bean and your business POJO stay in sync. Then, you are able to test the POJO instead of the bean. However, now, in order to implement a bean, we need to not only implement the bean interfaces (local and remote), but also our own interface.

So now, not only is the bean aware of its environment, through having to implement the bean interfaces, but it is also aware of the business rules as well because of our own interface that it implements. So even to test a bean’s functionality (which eventually does not exist in the bean anyway) we need to jump through hoops. Ugh.

Basically, my personal feeling, and that of many other people, including Sun is that EJBs (at least EJB 2.x) are fundamentally flawed. Thus they were rewritten for EJB 3.0 and the Java Persistence API (JPA).

If you want an excellent article detailing what is wrong with EJBs then check out Bruce Tate’s “Don’t Make Me Eat the Elephant Again“:http://today.java.net/pub/a/today/2004/06/15/ejb3.html.

2 Comments so far

  1. James J. on September 22nd, 2006

    Well what about scalability. How can you scale applications the way you can with EJB. Because with EJB you simply add another server with your EJB code and you’re good to go. How would you do it, the “non-EJB” way?

  2. fuzzylizard on September 23rd, 2006

    My initial answer to that question is actually twofold: first, I am not convinced that you can just “simply add another server” and get a true 1x scaling factor (i.e., double the throughput of the application) and second, I am not sure that using a distributed method of scaling is the right method of scaling an application. My second answer to your question is that I am not really sure. I have not worked with EJB applications enough to fully answer your question.

    Over and over again I keep hearing on the net two things, the first is that most real applications only use the web container and second that scalability is highly overused.

    I think that if you really do need an application that must service millions of transactions a day with 99.999% availability and must be distributed geographically, then EJBs may be the way to go.

    If I can find some links to better answers, I will post them because I realize that my answer is definitely lacking in evidence to support my opinions.

Posting your comment.

  • Search

  • Categories

    • .NET (2)
    • Agile (41)
    • Apple Mac (15)
    • Application Development (124)
    • Articles (4)
    • ColdFusion (2)
    • Demo/Tutorial (3)
    • Eclipse (1)
    • Flash (6)
    • General (567)
    • Git (1)
    • Google (1)
    • Hibernate (4)
    • J2EE (39)
    • Java (111)
    • Java Frameworks (5)
    • Links (1)
    • Linux (33)
    • Miscellanous (2)
    • NetBeans (3)
    • News (10)
    • Open Source (6)
    • Photography (2)
    • Programming (33)
    • Python (1)
    • Ruby (27)
    • Ruby on Rails (14)
    • Ruby on Rails Web Apps (1)
    • Software (14)
    • Spring (4)
    • Teaching (1)
    • TeamDocs (6)
    • Technology (2)
    • Test Driven Development (1)
    • Thoughts (33)
    • ThoughtWorks (8)
    • Tips and Tricks (1)
    • User Experience (1)
    • Web Design (7)
    • Web Development (37)
    • Wicket (1)
  • Archives

    • September 2009 (1)
    • June 2009 (1)
    • May 2009 (1)
    • April 2009 (7)
    • March 2009 (2)
    • February 2009 (6)
    • January 2009 (4)
    • December 2008 (3)
    • October 2008 (1)
    • September 2008 (2)
    • August 2008 (6)
    • July 2008 (4)
    • June 2008 (1)
    • May 2008 (8)
    • April 2008 (7)
    • March 2008 (2)
    • February 2008 (1)
    • January 2008 (5)
    • December 2007 (3)
    • November 2007 (4)
    • October 2007 (5)
    • September 2007 (2)
    • August 2007 (3)
    • July 2007 (6)
    • June 2007 (5)
    • May 2007 (5)
    • April 2007 (5)
    • March 2007 (6)
    • February 2007 (9)
    • January 2007 (16)
    • December 2006 (6)
    • November 2006 (15)
    • October 2006 (17)
    • September 2006 (27)
    • August 2006 (22)
    • July 2006 (14)
    • June 2006 (10)
    • May 2006 (18)
    • April 2006 (3)
    • March 2006 (6)
    • February 2006 (15)
    • January 2006 (7)
    • December 2005 (11)
    • November 2005 (8)
    • October 2005 (18)
    • September 2005 (24)
    • August 2005 (18)
    • July 2005 (21)
    • June 2005 (14)
    • May 2005 (23)
    • April 2005 (18)
    • March 2005 (34)
    • February 2005 (27)
    • January 2005 (27)
    • December 2004 (15)
    • November 2004 (17)
    • October 2004 (20)
    • September 2004 (10)
    • August 2004 (21)
    • July 2004 (9)
    • June 2004 (11)
    • May 2004 (4)
    • April 2004 (15)
    • March 2004 (12)
    • February 2004 (7)
    • January 2004 (17)
    • December 2003 (11)
    • November 2003 (8)
    • October 2003 (12)
    • September 2003 (12)
    • August 2003 (12)
    • July 2003 (23)
    • June 2003 (22)
    • May 2003 (14)
    • April 2003 (9)
    • March 2003 (22)
    • February 2003 (24)
    • January 2003 (32)
    • December 2002 (11)
    • November 2002 (16)
    • October 2002 (10)
    • September 2002 (9)
    • August 2002 (13)
  • Pages

    • About Me
    • Contact Me
    • Projects
    • Resume

Copyright © 2010 Chris Johnston
WordPress Theme based on Light Theme