Tải bản đầy đủ (.pdf) (764 trang)

Tài liệu Enterprise JavaBeans 3.1 ppt

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (5.71 MB, 764 trang )

www.it-ebooks.info
www.it-ebooks.info
Enterprise JavaBeans 3.1
www.it-ebooks.info
www.it-ebooks.info
SIXTH EDITION
Enterprise JavaBeans 3.1
Andrew Lee Rubinger and Bill Burke
Beijing

Cambridge

Farnham

Köln

Sebastopol

Tokyo
www.it-ebooks.info
Enterprise JavaBeans 3.1, Sixth Edition
by Andrew Lee Rubinger and Bill Burke
Copyright © 2010 Andrew Lee Rubinger and William J. Burke, Jr. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly
books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or
Editor: Mike Loukides
Production Editor: Teresa Elsey


Copyeditor: Genevieve d’Entremont
Proofreader: Teresa Elsey
Indexer: John Bickelhaupt
Cover Designer: Karen Montgomery
Interior Designer: David Futato
Illustrator: Robert Romano
Printing History:
June 1999:
First Edition.
March 2000: Second Edition.
September 2001: Third Edition.
June 2004: Fourth Edition.
May 2006: Fifth Edition.
September 2010: Sixth Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly
Media, Inc. Enterprise JavaBeans 3.1, Sixth Edition, the image of a wallaby and joey, and related
trade dress are trademarks of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.
ISBN: 978-0-596-15802-6
[M]
1283539129
www.it-ebooks.info
Table of Contents
Preface .

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xv
Part I. Why Enterprise JavaBeans?
1. Introduction .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
The Problem Domain 3
Breaking Up Responsibilities 3
Code Smart, Not Hard 6
The Enterprise JavaBeans™ 3.1 Specification 8
Review 10
2. Component Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Server-Side Component Types 12
Session Beans 12
Message-Driven Beans (MDBs) 15
Entity Beans 16
The Java Persistence Model 17
The Model Isn’t Everything 17
3. Container Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Dependency Injection (DI) 20
Concurrency 21
Instance Pooling/Caching 21
Transactions 23
Security 23
Timers 24
Naming and Object Stores 24
Interoperability 25
Lifecycle Callbacks 25
Interceptors 26
v
www.it-ebooks.info
Platform Integration 27

Bringing It Together 27
4. Developing Your First EJBs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Step 1: Preparation 29
Definitions 29
Naming Conventions 32
Conventions for the Examples 32
Step 2: Coding the EJB 33
The Contract 33
The Bean Implementation Class 34
Out-of-Container Testing 35
Integration Testing 36
Summary 39
Part II. Server-Side Component Models
5. The Stateless Session Bean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
The XML Deployment Descriptor 45
SessionContext 46
EJBContext 47
The Lifecycle of a Stateless Session Bean 49
The Does Not Exist State 50
The Method-Ready Pool 50
Example: The EncryptionEJB 52
The Contract: Business Interfaces 53
Application Exceptions 54
Bean Implementation Class 55
Accessing Environment Properties (Injection and Lookup) 57
Asynchronous Methods 60
6. The Stateful Session Bean .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
The Lifecycle of a Stateful Session Bean 64
The Does Not Exist State 65

The Method-Ready State 65
The Passivated State 66
Example: The FileTransferEJB 68
The Contract: Business Interfaces 69
Exceptions 70
Bean Implementation Class 70
POJO Testing Outside the Container 74
Integration Testing 77
vi | Table of Contents
www.it-ebooks.info
7. The Singleton Session Bean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Concurrency 82
Shared Mutable Access 84
Container-Managed Concurrency 86
Bean-Managed Concurrency 87
Lifecycle 87
Explicit Startup 87
Example: The RSSCacheEJB 88
Value Objects 89
The Contract: Business Interfaces 92
Bean Implementation Class 92
8. Message-Driven Beans . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
JMS and Message-Driven Beans 98
JMS as a Resource 98
JMS Is Asynchronous 99
JMS Messaging Models 100
Learning More About JMS 103
JMS-Based Message-Driven Beans 103
@MessageDriven 103
The Lifecycle of a Message-Driven Bean 108

The Does Not Exist State 109
The Method-Ready Pool 109
Connector-Based Message-Driven Beans 111
Message Linking 114
Session Beans Should Not Receive Messages 114
The JMS APIs 115
Example: The StatusUpdateEJBs 118
Part III. EJB and Persistence
9. Persistence: EntityManager . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Entities Are POJOs 128
Managed Versus Unmanaged Entities 130
Persistence Context 130
Packaging a Persistence Unit 133
The Persistence Unit Class Set 135
Obtaining an EntityManager 136
EntityManagerFactory 137
Obtaining a Persistence Context 138
Interacting with an EntityManager 140
Example: A Persistent Employee Registry 141
Table of Contents | vii
www.it-ebooks.info
A Transactional Abstraction 141
Persisting Entities 142
Finding and Updating Entities 144
Removing Entities 147
refresh() 148
contains() and clear() 148
flush() and FlushModeType 148
Locking 149
unwrap() and getDelegate() 149

10. Mapping Persistent Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
The Programming Model 152
The Employee Entity 152
The Bean Class 152
XML Mapping File 154
Basic Relational Mapping 155
Elementary Schema Mappings 155
Primary Keys 157
@Id 157
Table Generators 158
Sequence Generators 159
Primary-Key Classes and Composite Keys 160
Property Mappings 164
@Transient 164
@Basic and FetchType 164
@Lob 166
@Temporal 166
@Enumerated 167
@Embedded Objects 167
11. Entity Relationships . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
The Seven Relationship Types 171
One-to-One Unidirectional Relationship 173
One-to-One Bidirectional Relationship 176
One-to-Many Unidirectional Relationship 178
Many-to-One Unidirectional Relationship 181
One-to-Many Bidirectional Relationship 182
Many-to-Many Bidirectional Relationship 184
Many-to-Many Unidirectional Relationship 187
Mapping Collection-Based Relationships 188
Ordered List-Based Relationship 188

Map-Based Relationship 189
Detached Entities and FetchType 190
viii | Table of Contents
www.it-ebooks.info
Cascading 191
PERSIST 192
MERGE 192
REMOVE 193
REFRESH 193
ALL 193
When to Use Cascading 194
12. Entity Inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Single Table per Class Hierarchy 196
Advantages 198
Disadvantages 198
Table per Concrete Class 199
Advantages 200
Disadvantages 200
Table per Subclass 200
Advantages 203
Disadvantages 203
Mixing Strategies 203
Nonentity Base Classes 203
13. Queries, the Criteria API, and JPA QL .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Query API 206
Parameters 208
Date Parameters 209
Paging Results 209
Hints 210

FlushMode 210
JPA QL 211
Abstract Schema Names 211
Simple Queries 212
Selecting Entity and Relationship Properties 213
Constructor Expressions 215
The IN Operator and INNER JOIN 215
LEFT JOIN 216
Fetch Joins 217
Using DISTINCT 217
The WHERE Clause and Literals 218
The WHERE Clause and Operator Precedence 218
The WHERE Clause and Arithmetic Operators 219
The WHERE Clause and Logical Operators 219
The WHERE Clause and Comparison Symbols 219
The WHERE Clause and Equality Semantics 220
Table of Contents | ix
www.it-ebooks.info
The WHERE Clause and BETWEEN 221
The WHERE Clause and IN 221
The WHERE Clause and IS NULL 222
The WHERE Clause and IS EMPTY 223
The WHERE Clause and MEMBER OF 223
The WHERE Clause and LIKE 224
Functional Expressions 224
The ORDER BY Clause 228
Bulk UPDATE and DELETE 229
Native Queries 230
Scalar Native Queries 230
Simple Entity Native Queries 230

Complex Native Queries 231
Named Queries 232
Named Native Queries 233
14. Entity Callbacks and Listeners .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 235
Callback Events 235
Callbacks on Entity Classes 236
Entity Listeners 237
Default Entity Listeners 238
Inheritance and Listeners 238
Part IV. Container Services
15. Security . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Authentication and Identity 244
Authorization 245
Example: A Secured School 246
The Business Interface 246
Assigning Method Permissions 247
Programmatic Security 249
The RunAs Security Identity 251
16. JNDI, the ENC, and Injection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 255
Global JNDI 255
The JNDI ENC 256
What Can Be Registered in the JNDI ENC? 257
How Is the JNDI ENC Populated? 257
How Are Things Referenced from the ENC? 258
Reference and Injection Types 264
EJB References 264
x | Table of Contents
www.it-ebooks.info
EntityManagerFactory References 266

EntityManager References 269
Resource References 271
Resource Environment and Administered Objects 275
Environment Entries 275
Message Destination References 277
17. Transactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
ACID Transactions 279
Example: The BlackjackEJB 281
Helper EJBs for Testing Transactions 283
Is the BlackjackEJB Atomic? 284
Is the BlackjackEJB Consistent? 285
Is the BlackjackEJB Isolated? 285
Is the BlackjackEJB Durable? 285
Declarative Transaction Management 286
Transaction Scope 286
Transaction Attributes 287
Transaction Propagation 293
Isolation and Database Locking 298
Dirty, Repeatable, and Phantom Reads 298
Database Locks 299
Transaction Isolation Levels 300
Balancing Performance Against Consistency 301
Optimistic Locking 302
Programmatic Locking 303
Nontransactional EJBs 303
Explicit Transaction Management 304
Transaction Propagation in Bean-Managed Transactions 307
Heuristic Decisions 308
UserTransaction 309
Status 310

EJBContext Rollback Methods 312
Exceptions and Transactions 313
Application Exceptions Versus System Exceptions 313
Transactional Stateful Session Beans 318
The Transactional Method-Ready State 320
Conversational Persistence Contexts 321
18. Interceptors .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 323
Intercepting Methods 323
Interceptor Class 325
Applying Interceptors 327
Table of Contents | xi
www.it-ebooks.info
Interceptors and Injection 331
Intercepting Lifecycle Events 333
Custom Injection Annotations 333
Exception Handling 335
Aborting a Method Invocation 336
Catch and Rethrow Exceptions 336
Interceptor Lifecycle 338
Bean Class @AroundInvoke Methods 338
19. Timer Service . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 341
Example: A Batch Credit Card Processing System 342
The Business Interface 343
javax.ejb.ScheduleExpression and @javax.ejb.Schedule 344
The Bean Implementation Class 345
The TimerService 347
The Timer 348
Transactions 350
Stateless Session Bean Timers 351

Message-Driven Bean Timers 352
20. EJB 3.1: Web Services Standards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
Web Services Overview 355
XML Schema and XML Namespaces 356
XML Schema 356
XML Namespaces 361
SOAP 1.1 368
Web Services Styles 369
Exchanging SOAP Messages with HTTP 370
Now You See It, Now You Don’t 370
WSDL 1.1 371
The <definitions> Element 372
The <portType> and <message> Elements 374
The <types> Element 375
The <binding> and <service> Elements 377
UDDI 2.0 379
From Standards to Implementation 380
21. EJB 3.1 and Web Services .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 381
Accessing Web Services with JAX-RPC 381
Generating JAX-RPC Artifacts from WSDL 382
Calling a Service from an EJB 387
The <service-ref> Deployment Element 388
The JAX-RPC Mapping File 389
xii | Table of Contents
www.it-ebooks.info
Defining a Web Service with JAX-RPC 391
The WSDL Document 392
The Service Endpoint Interface 393
The Stateless Bean Class 393

The Deployment Files 394
Using JAX-WS 396
The @WebService Annotation 396
The @WebMethod Annotation 397
The @SOAPBinding Annotation 398
The @WebParam Annotation 399
The @WebResult Annotation 400
The @OneWay Annotation 401
Separating the Web Services Contract 401
The Service Class 402
The Service Endpoint Interface 403
The @WebServiceRef Annotation 403
Other Annotations and APIs 405
JAXB 405
Taking JAXB Further 407
Conclusion 407
Part V. Examples
A. FirstEJB Example .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415
B. Stateless Session EJB: Encryption Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 429
C. Stateful Session EJB: FTP Client Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453
D. Singleton Session EJB: RSS Cache Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505
E. Message-Driven EJB: Status Update Listeners Example .
. . . . . . . . . . . . . . . . . . . . . 527
F. Java Persistence APIs: Employee Registry Example . . . . . . . . . . . . . . . . . . . . . . . . . 557
G. Security: Secured School Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643
H. Transactions: Blackjack Game Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 663
I. Interceptors: TV Channel Service Example .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 691
Table of Contents | xiii

www.it-ebooks.info
J. Timer Service: Credit Card Processor Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 719
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 727
xiv | Table of Contents
www.it-ebooks.info
Preface
Author’s Note
Reluctantly succumbing to my father’s urging in the spring of 2000, I enrolled in my
first software development course at the University of Massachusetts. Following years
of frustration getting my computer to “just do what I want,” I quickly found our roles
inverted; I was in charge of the machine.
Academia proved a bit abstract to my sophomoric eyes, and after those first few months
of study, I yearned to make programs that delivered real user value. Endless trial-and-
error led me to the conclusion that it’s best not to write every little thing on your own—
it was more efficient to build upon the work of others.
By then the JBoss open source community was picking up steam with this thing called
an “Application Server,” a neat program that ran other programs. To a junior developer
it meant no more networking code. No more manual database connections. No more
object pools or caches. It meant no more speaking like a computer. It meant writing
the programs I wanted to build, not the mechanics underneath.
My experience with this enterprise software miraculously made me marketable enough
to snag a post-college job in the middle of the dot-com fallout, and during my tenure
there we enrolled in a weeklong training session from the source—JBoss, Inc.
The reputation of our instructor preceded his arrival, his name sprinkled about the
JBoss codebase, popular forums, and the upcoming EJB 3.0 specification. Bill Burke
came to deliver course material, but in my eyes he planted the seed that it’s possible to
become part of a greater community where people talk about software problems, cri-
tique one another’s ideas in public, and generally get paid to contribute to the global
computing effort.
Over the next few years I stayed active on the user forums and submitted patches,

looking to improve upon the new JBoss EJB3 container. One day my mail client blinked
with an incoming message from the team lead, Carlo de Wolf:
There is an opening for an EJB 3 developer in my team. Are you interested?
Why, yes.
xv
www.it-ebooks.info
The ethos of my development from inside JBoss and Red Hat have been the same as
they were from the start: keep application programmers writing application code.
One fall night at a team dinner, Bill extended to me the reins of his hugely successful
EJB book from O’Reilly, the same text that initially showed me the ropes. This edition
is the product of that discussion.
Who Should Read This Book
This book explains and demonstrates the fundamentals of the EJB 3.1 and Java Per-
sistence programming models. Although EJB makes application development much
simpler, it is still a complex technology that requires a great deal of time and study to
master. This book provides a straightforward, no-nonsense explanation of the under-
lying technology, Java™ classes and interfaces, the component model, and the runtime
behavior of EJB. It does not include material on previous versions of the specification,
however.
Although this book focuses on the fundamentals, it’s not a “dummies” book. EJB is an
extremely complex and ambitious enterprise technology. While using EJB may be fairly
simple, the amount of work required to understand and master EJB is significant. Before
reading this book, you should be fluent in the Java language and have some practical
experience developing business solutions. Experience with distributed object systems
is not a must, but you will need some experience with JDBC (or at least an under-
standing of the basics) to follow the examples in this book. If you are unfamiliar with
the Java language, I recommend Learning Java; this book was formerly Exploring
Java (both from O’Reilly). If you are unfamiliar with JDBC, I recommend Database
Programming with JDBC and Java (O’Reilly). If you need a stronger background in
distributed computing, I recommend Java Distributed Computing (O’Reilly).

How This Book Is Organized
This book is organized in five parts: Parts I through IV make up the technical manu-
script, while Part V comprises the examples. The technical manuscript explains what
EJB is, how it works, and when to use it. Part V provides step-by-step instructions for
installing, configuring, and running the examples.
The technical manuscript was adapted from Bill Burke and Richard Monson-Haefel’s
fifth edition of this book by yours truly, Andrew Lee Rubinger. The code contained
herein is not vendor-specific in any way, and it will often value concision over verbose
code samples. The intent of this section is to focus on conceptual understanding.
xvi | Preface
www.it-ebooks.info
Part I, Why Enterprise JavaBeans?
Multiuser distributed system are inherently complex. To ignore the issues they present
is to ask for trouble down the line. Luckily, you don’t have to do all the work yourself;
Chapters 1 through 4 outline the benefits of taking advantage of EJB—a component
model for simplified development of enterprise applications.
Part II, Server-Side Component Models
In Chapters 5 through 8 we dive into the mechanics of EJB with relation to business
logic. We’ll explore the various models available and discuss when each may be
appropriate.
Part III, EJB and Persistence
While the server-side component models typically speak to actions, the EJB Entity
model addresses the need to interact with persistent state. Java Persistence exposes
relational data as objects, and EJB comes with integration built-in. Chapters 9 through
14 cover these topics.
Part IV, Container Services
EJB is armed with a powerful feature set ensuring secure and consistent execution of
your application. Chapters 15 through 21 will uncover the utility and configuration of
these helpful services. Jason T. Greene adapted Chapters 20 and 21.
Part V, Examples

The examples workbook shows how to execute examples from those chapters in the
book that include at least one significant example. You’ll want to read the introduction
to the workbook to set up your build environment and configure it to run the examples.
After that, just go to the workbook chapter that matches the chapter you’re reading.
The examples themselves will have a release cycle that outlives this book, so you may
want to check back to get bug fixes, enhancements, and other updates as time goes on.
Software and Versions
This book covers EJB 3.1 and Java Persistence 2.0. It uses Java language features from
the Java SE 6 platform. Because the focus of this book is on developing vendor-
independent EJB components and solutions, we have stayed away from proprietary
extensions and vendor-dependent idioms wherever possible. You can use any EJB-
compliant server with this book, but you should be familiar with your server’s specific
Preface | xvii
www.it-ebooks.info
installation, deployment, and runtime-management procedures to work with the
examples.
Conventions Used in This Book
The following typographical conventions are used in this book:
Italic
Indicates new terms, URLs, email addresses, filenames, and file extensions.
Constant width
Used for program listings, as well as within paragraphs to refer to program elements
such as variable or function names, databases, data types, environment variables,
statements, and keywords.
Constant width bold
Shows commands or other text that should be typed literally by the user.
Constant width italic
Shows text that should be replaced with user-supplied values or by values deter-
mined by context.
This icon signifies a tip, suggestion, or general note.

This icon signifies a warning or caution.
Using Code Examples
This
book is here to help you get your job done. In general, you may use the code in
this book in your programs and documentation. You do not need to contact us for
permission; in fact, all example code has open source licensing. Selling or distributing
a CD-ROM of text from O’Reilly books does require permission, however. Answering
a question by citing this book and quoting example code does not require permission.
We appreciate, but do not require, attribution. An attribution usually includes the title,
author, publisher, copyright holder, and ISBN. For example: “Enterprise JavaBeans
3.1, Sixth Edition, by Andrew Lee Rubinger and Bill Burke (O’Reilly). Copyright 2010
Andrew Lee Rubinger and William J. Burke, Jr., 9780596158026.”
If you feel your use of code examples falls outside fair use or the permission given here,
feel free to contact us at
xviii | Preface
www.it-ebooks.info
Safari® Books Online
Safari Books Online is an on-demand digital library that lets you easily
search over 7,500 technology and creative reference books and videos to
find the answers you need quickly.
With a subscription, you can read any page and watch any video from our library online.
Read books on your cell phone and mobile devices. Access new titles before they are
available for print, and get exclusive access to manuscripts in development and post
feedback for the authors. Copy and paste code samples, organize your favorites, down-
load chapters, bookmark key sections, create notes, print out pages, and benefit from
tons of other time-saving features.
O’Reilly Media has uploaded this book to the Safari Books Online service. To have full
digital access to this book and others on similar topics from O’Reilly and other pub-
lishers, sign up for free at .
Comments and Questions

Please address comments and questions concerning this book to the publisher:
O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
800-998-9938 (in the United States or Canada)
707-829-0515 (international or local)
707-829-0104 (fax)
There is a web page for this book, which lists errata, examples, and any additional
information. You can access this page at:
/>To comment on or ask technical questions about this book, send email to:

For more information about books, conferences, software, Resource Centers, and the
O’Reilly Network, see the O’Reilly website at:

Preface | xix
www.it-ebooks.info
Acknowledgments
Many individuals share the credit for this book’s development and delivery. Michael
Loukides, the editor, and his team were pivotal to the success of every edition of this
book. Without their experience, craft, and guidance, this book would not have been
possible. I want to thank Jason T. Greene for taking over the web services chapters. I
had no desire to learn JAX-WS beyond the @WebService annotation. Without the earlier
work of Richard Monson-Haefel and Bill Burke, this book would not have been pos-
sible. It amazes me how the structure of this book could last six editions, and it is a
testament to Bill and Richard’s ability to succinctly structure complex topics into a
cohesive text.
I particularly want to thank Bill for passing the baton to me on this series. A champion
of my career from early on, you’ve encouraged me to get involved in coding, blogging,
and accepting new challenges. You’ve been a force in our industry since I was learning
a “for” loop, and your continued relevance now in the REST world is incredibly

inspiring.
My coworkers, both within JBoss and around the community, have played no small
part in the success of my software and this book.
Carlo de Wolf, whether he likes it or not, has been the technical mentor every developer
should have. He’s invested continually in my growth for years, and it’s difficult to
understate my appreciation for both his guidance and friendship.
Jaikiran Pai rounds out our EJB3 team at JBoss. Like me, he came from the community,
and his dedication to our users and others in our group is noticeable every day, without
fail, on our forums and mailing lists. You are certainly a jack of all trades.
The Application Server team and members of the #jboss-dev Freenode IRC Channel
comprise a support system without which my code would surely be deficient. David
Lloyd, Jason Greene, Brian Stansberry, Ales Justin, and Bob McWhirter: you boys are
brilliant and selfless.
Our newly minted JBoss Testing team brings dedication to usability to a new level.
Aslak Knutsen, Dan Allen, and Pete Muir: your work has made the examples portion
of this book possible, and I’ve no doubt that we’re on the cusp of a revolution that will
bring simplicity back to functional testing of Enterprise Java. Let’s keep plugging.
The JBoss Boston User’s Group gave me a stage and place to geek out with friends.
Until the next meeting, Jesper Pedersen, Shelly McGowan, Scott Marlow, and John
Doyle.
Tim Roberts: You employed me as a college kid and let me learn open source on your
dime. It was trial by fire, and I thank you for not breaking out the extinguisher before
I developed my chops.
Marc Elliott and Matt Warren: You gave me my first job out of school, and your pa-
tience in cultivating a useful employee out of me will always be remembered.
xx | Preface
www.it-ebooks.info
Brian Weisenthal and Morgan Lang of 9mmedia in New York City: Together we built
some of the slickest-looking applications I’ve seen to this day. You’re deeply successful
in rich media, and it was a pleasure building the backend for such impressive software.

Thank you for graciously allowing me to pursue a career at JBoss.
Many expert technical reviewers helped ensure that the material was technically accu-
rate and true to the spirit of EJB and Java Persistence. Of special note are Trenton D.
Adams and Juraci Paixao Krohling, who’ve sent great comments throughout the
process.
I’d also like to thank my personal entourage, though their influence was mostly detri-
mental to the completion of this book. Prelack, Fleischer, Halbert, Rudman, Clark:
You locked me in a moving car and kidnapped me to a casino the weekend before my
first draft was due. Jonathan Adam: You’re smart and fair, and long ago eclipsed me
in any number of ways. No brother could ever be more proud than I am of you.
Grandma Natalie and Grandpa Jerry Glass, you’ve invested in my education and have
encouraged my intellectual curiosity. And you make the best bagels-n-lox breakfast
known to man.
Mom and Dad, you supported me when you disagreed with me. You whipped me into
shape when I was lazy. You’re excellent at your jobs, and you’re even finer human
beings. Thank you for being such an excellent example.
Preface | xxi
www.it-ebooks.info
www.it-ebooks.info
PART I
Why Enterprise JavaBeans?
If your path to Enterprise Java is anything like mine, you’ve arrived here hoping to be
more productive in application development. Perhaps you’ve heard some good or bad
things about this thing called “EJB,” and you’d like to explore some more. Perhaps
some EJB technology is already in place at work, and you’re looking to understand it
a bit deeper.
The fact is that Enterprise JavaBeans is much more than a set of APIs. It is a simplified
programming model that, when understood at a conceptual level, has the power to
easily adapt lightweight Java classes into powerful business components. In short, EJB
lets you focus on the work you do best—writing your application logic.

In this section we’ll start with a bird’s-eye view of the issues facing every software
developer, examining how EJB removes common problems from your concern.
www.it-ebooks.info

×