EJB 3 in Action, Second Edition
Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan
Copyright
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email:
orders@manning.com2014 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps.
Recognizing the importance of preserving what has been written, it is Mannings policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine.
| Manning Publications Co.20 Baldwin RoadPO Box 261Shelter Island, NY 11964 | Development editor: Nermina MillerCopyeditor and project editor: Jodie AllenProofreaders: Linda Recktenwald, Melody DolabTechnical proofreader: Deepak VohraTypesetter: Dennis DalinnikCover designer: Marija Tudor |
ISBN: 9781935182993
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 EBM 19 18 17 16 15 14
Brief Table of Contents
Table of Contents
Praise for the First Edition
This is the EJB book to read! Dont miss its practical advice.
Jeanne Boyarsky, JavaRanch.com
A technical book that is surprisingly entertaining.
King Y. Wang, Oracle Canada
Great bookcovers everything relating to EJB 3.
Awais Bajwa, Expert Group Member JSR 243 Java Data Objects
Well-written, easy, and fun.
Patrick Dennis, Management Dynamics Inc.
Written with a wide audience in mind ... not just a recitation of the EJB specification ... includes a lot of practical advice. Has a light, humorous, and accessible style of writing and all the concepts are illustrated with examples.
One Minute Review from javalobby.org
Broad coverage of EJB 3 with a very simple and excellently crafted case study. The book starts lightly on this complex subject and slowly dives into the details of advanced concepts like interceptors, transactions, security, JPA, and performance issues, developing each scenario in the case study. Overall, a very good book and a very smooth read.
Amazon.com reader
Preface
In its early days, EJB was inspired by the distributed computing ideas of technologies such as CORBA and was intended to add scalability to server-side applications. EJB and J2EE enjoyed some of the greatest buzz in the industry during the dot.com boom.
The initial goal for EJB was to provide a simpler alternative to CORBA through the benefits of a standard development framework and reusable components. By the time EJB 2 was released, it became apparent that the EJB framework could become the new standard for server-side development. The framework provided Enterprise developers with everything they neededremoting, transaction management, security, state maintenance, persistence, and web servicesbut it was heavyweight, requiring developers to focus more on the framework itself than on the requirements of their business applications. Because EJB was loaded with more features, its inventors failed to address its growing complexity.
As the community became disenchanted with the limitations of EJB 2, innovative open source tools emerged. These tools were signs of the increasing discontent with the complexities of Java EE. Though well-intentioned, these tools made Enterprise development even more complex since they deviated from the standards of the application server they were to run in. It was time for the Java Community Process (JCP) and expert groups to work on the simplification of Java EE development. That was the sole motivation behind Java EE 5 and the goal of the EJB 3 expert group.
For a technology with a wide deployment base, the changes that came with EJB 3 were nothing short of stunning. EJB 3 successfully melds innovative techniques to make component development as easy as possible. These techniques include the use of annotations, metadata programming, dependency injection, AspectJ-like interceptors, and intelligent defaulting. The heavyweight inheritance-based programming model was abandoned in favor of Plain Old Java Object (POJO) programming, and the verbose XML descriptor was now out of the developers way.
The changes to the persistence model were particularly dramatic. EJB 3 left behind the flawed EJB 2 Entity Beans model in favor of the lightweight Java Persistence API (JPA). Unlike Entity Beans, JPA is not container-based. It has more in common with open source object relational mapping (ORM) tools that emerged in the community in response to Entity Beans complexity. JPA can be used either inside or outside a Java Enterprise server and is now the de facto persistence standard for Java. Its Java Persistence Query Language (JPQL) standardizes object relational queries but also supports native SQL queries if the need arises.
The changes made in EJB 3 have been well received in the Java community. Its simplified specification has led to its wide adoption in new projects. More and more companies are giving the once ugly EJB technology another look and they like what they see. With the release of EJB 3.2, the adoption will continue to grow. EJB 3.2 has made support for EJB 2 optional so that older technology can finally be sunset and innovations in EJB 3 can continue to grow. EJB 3.2 has also seen major enhancements to message-driven beans (MDBs), making messaging much easier. EJB 3.2 made improvements to stateful session bean passivation and session bean local interfaces, as well as dramatic improvements to the timer services. All this and more await you in EJB 3.2.
Since EJB is POJO-based, every Java developer can easily become an EJB developer. Simple annotations give your business logic safe transaction management, security, and exposure as web services for easy interoperability in your company. We strive to keep our book different from other books on EJB by providing practical examples, best practices, and tips for performance tuning. We highlight whats new in the EJB 3.2 specification, which gives you more tools for your development. We hope this revised edition will help you to quickly learn how to use EJB 3 effectively in your next Enterprise application.
Acknowledgments
Authoring a book requires great effort and its difficult to list everyone who helped us during this project. First and foremost wed like to thank everyone at Manning for their encouragement and support, especially publisher Marjan Bace, associate publisher Michael Stephens, and our editor Nermina Miller. Wed also like to thank others at Manning who worked on different stages of the project: review editor Olivia Booth; project editor Jodie Allen; development manager Maureen Spencer; technical proofreader Deepak Vohra, who performed a final review of the book shortly before it went to press; Linda Recktenwald and Melody Dolab, who edited, proofread, and polished our prose; and typesetter Dennis Dalinnik, who converted our Word documents into a real book! Thanks also to all of those who worked behind the scenes to help get our book published.