REVIEW - Beginning EJB 3 Application Development - From Novice to Professional


Title:

Beginning EJB 3 Application Development

From Novice to Professional

Author:

Raghu Kodali, Jonathan Wetherbee, Peter Zadrozny

ISBN:

Publisher:

Apress (2006)

Pages:

512pp

Reviewer:

Peter Pilgrim

Reviewed:

June 2007

Rating:

★★★☆☆


This book is about beginning EJB 3 development. If you have left the planet of Enterprise Java for a few years, you would be forgiven for missing the political decisions that caused the JCP change its direction from design-by-committee to embracing the de facto practices of the community. Therefore first chapter of the book introduces the brief history of the EJB 3 standard. The authors explain where the EJB specification fits in within the Java EE 5 standard. There are plenty of source code examples throughout the book, and readers should note that the examples in the book were built against the Sun supported Glassfish application server. The authors luckily show you not only how to download the server and set it up accordingly, but how to launch it. Following the instructions therein I had the Glassfish server up and running in no time at all. At the time of writing Glassfish has reached 1.0 release, so please note the text may already be slightly out-of-date by the time this review is published [in fact Sun are debut version2.0 beta]. Later chapters depend on the existence of an Oracle database server by default, but because the code is standard Java EE, then it should be at least be portable to another application server and database server combination.

The second chapter opens with Session EJBs. Here the basic concepts and differences between stateless and stateful beans are well explained. I felt the liberal use of annotations and the early introduction of dependency injection wholly appropriate to the examples. EJB 3 Interceptors also debuted, and wisely the authors avoided the debate, which involved interceptors being so similar to AOP, and why does Java not support AOP in the language by default. For a stateless session beans the authors chose a search facade bean of the type that you find in any ecommerce application. For the stateful example what else would you choose as learning tool other than a shopping cart bean. The second chapter concludes with compiling, packaging, and deploying to Glassfish. There is a definite sequence of events here. An explanation followed by the code, which is then followed by deployment. This is the pattern for the rest of the book mostly, and of course. Variations on a theme depend on the chapter's context, which can include setting up application server resources as well.

From sessions EJBs, we moved quickly on to entity EJBs in chapter three and here the Kodali and Wetherbee provide background into the new Java Persistence API. If you have experienced development with JBoss Hibernate or Oracle's TopLink then you will find the material not so unfamiliar. The first example is a customer bean as you would hope to find on Amazon.co.uk. A tricky part of this subject, I felt, was handled fairly well. One can place annotations on an object's instance variables or a JavaBean accessors, but not both. As a beginner you may have to read that text a few times, and this is a minor criticism of the chapter. However, the pros and cons of each approach are clearly laid out. There is coverage of generating sequences, or rather using database provided native sequences, and also composite keys. The latter you will see in any self-respecting application that calls itself commercial. For some of the source code I felt it could have done with embolden text, but that is a publishers decision, and not necessarily the authors' fault. Chapter three also introduces the entity managers and its associated factories. The readers is also introduced to persistence archive file and most importantly how define relationships between entities. Kodali and Wetherbee have examples of all the cardinalities (one-to-one, one-to-many, many-to-one, and many-to-many). Finally Java Persistence Query Language, named queries, and bulk operation are placed at end of the chapter.

Chapter four takes the basic JPA knowledge to a more advanced level. There are, thankfully, full descriptions of the three persistence strategies that take care of polymorphic inheritance hierarchies. This is the three official strategies to allow persistence of sub classes and their hierarchies to you and me. The authors describe the standard support for optimistic locking, embeddable, non-entity classes and polymorphic queries. EJB3 also has support for ejecting native SQL, and there is one example extract that illustrates this. Also in this chapter is a useful design note, which is devoted to a comparison of O/R implementations approaches.

Message driven bean are covered in the fifth chapter, which introduces the concept of queues and topics. Much of the technology remains the same as it was in EJB 2.1 except for the callback methods and the fact that interceptors can be applied to MDBs.

With EJB 3 it is very easy to make any method in a stateless session EJB act as a web service. This is because the actual EJB 3 specification based its task on so-called ease-of-development for the programmer. Chapter six is all about applying web services to EJBs. It starts with the basic concepts of WSDL, UDDI, and SOAP. Although there is just limited information, you would need another couple of books on web services for more concise information, nevertheless the code and explanation are clear to the eye. A credit service demonstrates the EJB 3 web service.

By page 205, which is roughly the middle of the book, we find in chapter 7 coverage of the integration of session beans, entities, message driven beans and web services. This is the large practical review of a full EJB 3 application, the wine store that ties all the previous concepts together. The wine store is fortunately not trivial, as a learning tool, I felt, it really does demonstrate the ease-of-deployment mandate of the new APIs included the annotations. Most of the older boilerplate try/catch logic and checked exceptions around JNDI lookups have gone away. It makes for cleaner source code, more readability. In the book's code there were some minor typographical layout issues but nothing should deflect from the standard of code and the commentary. This seventh chapter is just under 50 pages long, but it just as well, because it could be view as a reference chapter of the book. I think many EJB 3 engineers could refer back to it.

The next chapter covers the subject of transaction support in EJB 3 and the two different kinds bean managed transactions and container managed transactions. There is a brief overview of ACID acronym and reasons behind transactions. The authors discusses the issues between various strategies of transaction management. For example transaction scope persistence context is a standard demarcation in a persistence context. It demarcates whether the persistence context life-cycle in relation to the life of a transaction. Also an all too short explanation of distributed transaction management (JTA) versus local entity manager resources (JDBC). However there are two examples in the book. The first is a stateless session bean with a CMT demarcation, and the second is a stateful session bean with BMT demarcation. The authors state the pros and cons of each example very well.

The later chapters in the book after transactions consider the performance testing of EJB 3 components. There is a short description of gathering metrics such as the aggregate average response time. The authors based their performance analysis on an open source load testing framework called Grinder, which is Jython program. It appears to be useful tool for developers to know, but readers may have their favourites however.

If the reader has experience of writing EJB 2 applications, then chapter 10 will be useful to read, especially if one is tasked to port an legacy J2EE application to the new API. Session EJB are treated first as one can expect the home and remote interfaces can disappear. These are now annotations in Java 5. The authors provide reference material in tabular format, and the advice is great, and it will help with specifying the correct annotations on the corresponding container callback methods. This approach also applies to MDB and entity EJB migration. We can applaud the authors for including a end-to-end EJB application migration example with an deployment descriptor file. The legacy application is a human resources application. Kodali and Wetherbee provide the final conversion of this to an EJB 3 application including the client program as well. The explanation is comprehensible and rather detailed. Most impressively they demonstrate how to run this HR application outside of the container using the EJB 3 entity manager. The chapter is forty four pages long and it is readily available reference for an intermediate engineer.

The remaining chapters cover EJB 3 deployment and client applications. The task of deployer persons is pretty much important to those administrators who have to configure a new EJB application. A developer should know what the configuration points are and the authors deliberately overfill the reader with plenty of materials. For the client side authors have chosen to take a higher level approach, and discuss firstly associated blueprint architecture, especially the evolution of Java EE web technologies. Not surprisingly the Kodali and Wetherbee decided that Java Server Faces is the way to go, so the reader will find a demonstration of a wine store web application at the end of the book. Whilst JSF is not to every one's nulls fancy, there is enough code and salient description to transfer this knowledge to another web framework like Struts or Spring MVC. There is one appendix that describes the EJB2 vs EJB3 performance. Perhaps the authors missed a trick by not adding single reference chapter with all the known annotations in the specification.

The book has lots of examples and screen-dumps of calling javac by hand, thankfully the source code does have Ant build XML files. If you are looking to run the examples on something other than Glassfish then you may be disappointed, if you want to use Maven 2.0 then you are really out of luck, but hey this is "soft" wear not hardware. I don't think the software is difficult to port over to another database and/or application server. If you are advanced user hoping to find out how to integrate EJB 3 with Spring Framework or how it all fits together with Hibernate, then you probably should look elsewhere.

This is a book that I would recommend highly to beginners, because the Java EE universe is so much bigger than it was five years ago. The text, therefore, is suitable for new developer who have been given an EJB 3 project. The book more than a book about persistence it does cover a lot of the Java EE material to do with EJB 3, it is worthy of a place next to your workstation.


Book cover image courtesy of Open Library.





Your Privacy

By clicking "Accept Non-Essential Cookies" you agree ACCU can store non-essential cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

Current Setting: Non-Essential Cookies REJECTED


By clicking "Include Third Party Content" you agree ACCU can forward your IP address to third-party sites (such as YouTube) to enhance the information presented on this site, and that third-party sites may store cookies on your device.

Current Setting: Third Party Content EXCLUDED



Settings can be changed at any time from the Cookie Policy page.