We decided to review the book Enterprise JavaBeans 3.1 because it’s one of the technologies we actually use to develop Yougi. We genuinely love this technology and this book is very valuable as a reference to make the best use of EJBs. If you have a web profile or a full stack app server, then EJBs are the way to go for your business components.
Of course EJBs are not the solution for every problem. We wouldn’t recommend it to develop content-based websites, games, or desktop applications (although it is possible). EJBs were designed for server-side and highly transaction business-oriented applications. It’s unfair to criticize it out of this context. The technology was designed taking into account the consensus of many industrial parties, coordinated by the Java Community Process (JCP). For every new release they come out with a formal specification that is used by the industry to provide competitive implementations with exactly the same functionalities.
The book is very comprehensive, making it work like a reference book. It even contains a whole part dedicated to Java Persistence API (JPA), which we think it’s too much because there are so many details in JPA that it would deserve a dedicated book. That’s why we noticed this part of the book a bit superficial. Apart from that, the book is full of working code, the authors try hard to be vendor-independent and, of course, it’s a quality assured O’Reilly book.
The EJB 3.2 specification went final in May, 2013, but EJB 3.1 is still the latest production-ready release provided by all major players in the enterprise market. Many people agree that EJB 3.0 was a game changing for the JavaEE platform since the disastrous EJB 2.x architecture. We disagree. I think the real game changing came in EJB 3.1, when the technology became more mature and competitive in comparison to Spring. Even when you pick EJB 3.2, you see there is no fundamental change to the model. Just addition of new features. Having said that, you won’t lose any relevant knowledge by deciding to learn EJB 3.1 now instead of waiting so long for a brand new EJB book coming out. The book Enterprise JavaBeans, published by O’Reilly, is the only one I know with the richest set of details about this technology.
What would you use EJBs for? Basically, when you want to simplify the implementation of the business logic directly related to the management of relational data. The convention is that the container will manage the transactions for you and all the complexity behind inserting, deleting, updating and querying the database. The code becomes very clean and easy to read. In addition, any business method can be exposed as a web service with just a few annotations.
On the other hand, if you don’t use a relational database or use a NoSQL database, probably EJBs are too much for your needs. You can still use them to simplify the implementation of singletons, schedule the execution of methods asynchronously, and consume data from queues, but the real added value is its robustness to keep your data consistent without boilerplate code.
Fork Yougi’s project on GitHub to see how we make use of EJBs.