Thursday, November 16, 2006

Learnings from a discussion on EJB 3.0

Yesterday I had a learning discussion session with some developers on EJB 3.0 It was a very interesting discussion and we all took home some new and interesting stuff. The key learnings were:

  1. EJB 2.1 was a 300 lb gorilla that used a crane to lift a peanut. EJB 3.0 is a nimble chimpanzee :-)
  2. EJB 3.0 uses annotations instead on the xml deployment descriptors that were so hard to maintain. So beans, security constrains and everything that was earlier defined using the deployment descriptor can now be done in code using annotations. I think this is really neat, especially for small applications.
  3. We no longer need to define all the 2.1 interfaces to get an EJB working. In fact we need not define interfaces at all. A business interface will be automatically created for us by the annotation processor. I read somewhere on the net (do not remember where), that we must not generate the business interface automatically (but create it manually and have the EBJ implement it), because the automatically generated interaface will include every public method from the bean and make it available to client code. Now I think that should not be a problem. Public methods are meant to define the public interface of a class, so if we do not want client code to invoke a method, then it should not be public. So the existence of public methods that should not be available to client code, smells to me of bad design.
  4. EBJ 3.0 entity beans are now POJO's, which is again really nice and makes development light weight. Again a big plus for small applications, and for maintainability.
  5. EBJ 3.0 uses dependency injection. The container will inject environment related objects in the client automatically. Client code now does not need to do any complex JNDI lookups. By the way Martin Fowler has written an excellent article on dependency injection here.
  6. We can still use deployment descriptors to override annotations, but in my opinion this should be avoided (unless absolutely necessary), because it will make the application harder to maintain.
Overall EBJ 3.0 is a huge advancement towards easing enterprise development. I am certain this specification will be adopted and accepted by the developer community much better than the previous one.

No comments: