Home > Store

Enterprise JavaBeans Component Architecture: Designing and Coding Enterprise Applications

Register your product to gain access to bonus material or receive a coupon.

Enterprise JavaBeans Component Architecture: Designing and Coding Enterprise Applications


  • Sorry, this book is no longer in print.
Not for Sale


  • Copyright 2002
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-035571-2
  • ISBN-13: 978-0-13-035571-3

Proven techniques and patterns for enterprise development.

  • Design guidelines for EJB 2.0 component architecture
  • Powerful patterns for enterprise application design
  • Extensive real-world code examples
  • Covers every type of component, including message-driven beans

This book simplifies the creation of well-designed enterprise applications using the upgraded Enterprise JavaBeans 2.0 specification. Experienced Java platform mentors Gail Anderson and Paul Anderson use detailed code examples to introduce every key skill involved in creating components, stand-alone Java platform clients, and JavaServer Pages API clients. They introduce powerful EJB platform design patterns, and show how to apply them in real-world projects while avoiding critical errors in application design. Using actual business components, the authors show how to make the most of these key EJB component architecture features:

  • Stateless and stateful session beans
  • Entity beans with bean-managed persistence
  • Entity beans with container-managed persistence
  • Container-managed relationships
  • Local and remote interfaces
  • The Enterprise JavaBeans Query Language
  • EJB 2.0 specification message driven beans

Each chapter includes a "Design Guidelines and Patterns" section designed to help you assess tradeoffs associated with your design decisions, and key point summaries that tie together important concepts. In short, Anderson and Anderson give you everything you need to build EJB 2.0 platform applications with maximum robustness, scalability, and performance.

Everything you need to take full advantage of the EJB 2.0 specification:

  • Extensive code examples—real-world business components with just enough complexity to explain subtle design issues
  • How to apply J2EE platform design patterns—Value Object, Data Access Object, Value List Iterator, and Session Fa¿ade Pattern
  • Design guidelines for building distributed applications that avoid common pitfalls
  • Expert insight into matching enterprise beans to application requirements
  • Crystal-clear explanations of the key concepts that make EJB technology so powerful

Sample Content

Online Sample Chapters

Enterprise JavaBeans Overview

The Benefits of Stateful Session Beans

Table of Contents


About the Front Cover.


1. Introduction.

What Is the Enterprise JavaBeans Architecture? How This Book Is Organized. Our Vision. Reader Audience. About the Examples. Source Code Online.

2. Enterprise JavaBeans Overview.

The J2EE Architecture. The J2EE Components. The J2EE Application Server. Enterprise JavaBeans. Key Point Summary.

3. Stateless Session Beans.

Introducing Stateless Session Beans. The Loan Enterprise Bean. Stand-alone Java Application Client. Web Component Client (JSP Client). Design Guidelines and Patterns. Key Point Summary.

4. Session Beans with JDBC.

Session Beans and JDBC. Music Stateless Session Bean. A Java Swing Application Client. JSP Web Component Client. Data Access Object Pattern. Design Guidelines and Patterns. Key Point Summary.

5. Stateful Session Beans.

Introducing Stateful Session Beans. MusicCart Stateful Session Bean. Value List Iterator Pattern. Web Component Client. Local Interfaces. Design Guidelines and Patterns. Key Point Summary.

6. Entity Beans with BMP.

Introducing Entity Beans. Customer Entity Bean. Entity Bean Test Client. Transaction Overview. Session Facade Pattern. Web Component Client. Design Guidelines and Patterns. Key Point Summary.

7. Entity Beans with CMP.

Introducing Container-Managed Persistence. The Three Entity Beans. Session Facade Pattern. Web Component Client. Administrator Client. Design Guidelines and Patterns. Key Point Summary.

8. Message-Driven Beans.

Messaging Architectures. Introducing JMS. Designing Message-Driven Beans. Student Message-Driven Bean. ShipOrder Message-Driven Bean. Design Guidelines and Patterns. Key Point Summary.

Appendix A.

MusicApp Swing Application.




Topics in This Chapter

  • The Enterprise JavaBeans? Architecture
  • How This Book Is Organized
  • Our Vision
  • Reader Audience
  • About the Examples
  • Source Code Online

Distributed computing has always had tough problems to solve: security, concurrency, database transactions, data integrity, and performance requirements, to name a few. How does the Java 2 Platform, Enterprise Edition (J2EE) address these issues and what is the role of the Enterprise JavaBeans architecture?

As we describe the Enterprise JavaBeans component architecture, let's define where we hope to go, how we hope to get there, and who we hope to take with us. The software industry has exciting offerings right now and in the near future. The architecture of loosely coupled components promises to offer flexibility, scalability, and portability. There is no better time than now to delve into the world of distributed component computing!

1.1What Is the Enterprise JavaBeans Architecture?

The Enterprise JavaBeans (EJB) architecture is a specification developed at Sun Microsystems. It describes a component-based architecture that provides for the development and deployment of distributed applications. The specification details the services and requirements of an application server which manages EJB components. It also describes coding requirements that bean developers must follow to create portable applications. The lofty and worthwhile goal is for bean developers to write EJB components once and deploy them on any application server that is compliant with Enterprise JavaBeans technology. Furthermore, the EJB architecture makes enterprise applications scalable, secure, and transactional.

Enterprise JavaBeans are components that execute within an "EJB container," under the supervision of an application server. There are three main EJB types: session, entity, and message driven. Furthermore, session beans come in two flavors: stateless and stateful. The application server and EJB container provide system services for EJBs, such as data persistence, transactions, security, and resource management. The EJB container maintains pools of database connections, as well as pools of EJB instances that can be assigned to clients as needed.

The Java 2 Platform, Enterprise Edition (J2EE) is an industry-standard suite of Java APIs for enterprise computing from Sun Microsystems. It includes the Enterprise JavaBeans architecture and a set of related packages that make everything work together. For example, a Java client may use the Java Naming and Directory Interface (JNDI) to look up the location of an EJB component. The application server, which provides the system services that make EJBs work, uses Java Remote Method Invocation (RMI) and RMI-IIOP to implement remote calls across a network. Message-driven beans, a new type of EJB, use the Java Message Service (JMS) to provide a bean capable of responding to messages. So, while Enterprise JavaBeans technology provides specific services in the realm of enterprise computing, it is part of a larger picture. This picture is inscribed by J2EE and its many independent packages that provide specific services.

Why should developers care about J2EE and EJB? Because the application server manages an EJB and provides the system services we mentioned, bean developers can concentrate on designing enterprise applications that adhere to specific business requirements. Instead of writing transactional database code, bean developers can pay attention to business rules, business processes, and how to best keep track of business data. Furthermore, as J2EE technology matures, commercial application servers that support this specification will become more numerous. Better still, as these J2EE application server products improve, the same enterprise application written today will perform better tomorrow-unchanged-because the application server will provide a better implementation.

1.2How This Book Is Organized

The chapters follow a gradual progression from the simplest type of EJB (stateless session with no database access) to a complete enterprise application with eight EJBs, one web component, and multiple application clients. It's best to read the chapters in this order.

Chapter 2 begins with an overview of the Enterprise JavaBeans architecture. This chapter introduces the J2EE components and explains the role of the application server and container in managing EJBs and the system services they use. You should read this material first if you are new to enterprise beans, but even experienced developers may find it necessary to return to this chapter from time to time. By doing this, you discover how everything fits into the big picture.

Chapter 3 introduces the simplest EJB component, the stateless session bean. Our example, Loan EJB, is a component that produces amortization tables and monthly payment amounts for long term fixed-rate loans. We introduce the Value Object Pattern. After giving you an overview of Java Server Pages (JSP), we also present our first web component client.

Chapter 4 presents Java Database Connectivity (JDBC) with EJBs. In this example, we use a stateless session bean as a database reader. After introducing the basics of JDBC, we show you how to use an EJB for read-only database access. We implement the Data Access Object (DAO) Pattern and explain how to customize an application with a deployment descriptor. The chapter also presents a Swing application client (complete source listing found in Appendix A) and a JSP web component client.

Chapter 5 presents stateful session beans and contrasts them with stateless session beans. This is the beginning of our online shopping application example. Our stateful session bean, MusicCart EJB, is a virtual shopping cart that holds items selected by customers running a JSP web component client. We also introduce the Value List Iterator Pattern and explain EJB local interfaces.

Chapter 6 introduces entity beans. Although our example uses Bean-Managed Persistence (BMP), the reader should be familiar with the material in this chapter because much of it applies to entity beans in general. We present entity bean finder and home methods. Our example is Customer EJB, an isolated "customer" entity bean with BMP. We use the DAO pattern for the persistence implementation. We introduce the very important Session Facade Pattern and local interfaces with entity beans. We enhance our JSP web component client to perform customer lookup and verification against the persistent datastore.

Chapter 7 continues with entity beans. We now explore Container-Managed Persistence (CMP) and Container-Managed Relationships (CMR). We introduce EJB QL, the J2EE query language required to specify custom finder semantics and select methods. Our example includes three related entity beans: Customer EJB, Order EJB, and LineItem EJB. We describe the expanded role of local interfaces and revisit the Session Facade Pattern. The JSP web component client creates customer orders using the data collected in the stateful session MusicCart EJB presented in Chapter 5. The full application now contains seven EJBs, one web component, and an administrative client to inspect the database.

Chapter 8 introduces message-driven beans, the newest EJB component. We begin with an overview of the Java Message Service (JMS) and explain the Publish-Subscribe and Point-to-Point messaging models. Messaging provides a loosely coupled architecture that can enhance the performance of enterprise applications. Our first example is a Message-Driven Bean (MDB) that provides a response mechanism to a client. Our final example is a Java client which sends a message to a ShipOrder MDB. The ShipOrder MDB interfaces with the previously written Session Facade to request the shipment of certain customer orders.

1.3Our Vision

Enterprise JavaBeans technology is not an easy topic. Yet we believe EJB to be a significant offering in the enterprise computing arena. For the first time, there exists a specification that allows bean developers to write transactional, multi-user, scalable enterprise applications without being experts in transactions, multithreaded programming, security, or database programming. Pulling the enterprise system services out of the components and standardizing them within an application server has tremendous benefits. The most obvious benefit is that we leave the implementation of these system services to developers who are experts in enterprise issues. As the technology matures, the application servers will get better, and our enterprise applications will in turn run better.

Does this make EJB authoring simplistic? Not hardly. But it makes EJB authoring accessible and portable across multiple platforms. Our vision is to create a text with examples that teach, not just how to create an EJB, but how to design components that work best within the framework of a particular application. We strive to create examples that show you when to use an entity bean, not as an isolated entity bean example, but as a component within a whole, real-world application.

The industry is learning as pockets of developers here and there build on experiences. We learn what works and what doesn't. And from these battles with reality emerge design patterns that address common problems. So, along with our examples, we've also attempted to attack some of these problems. We show you how to apply commonly accepted design patterns to your enterprise designs (and why). Our hope is that you can take our examples and build your own solutions more quickly with an understanding of the design trade-offs that you'll make.

As you wind your way through these examples, we hope your EJB journey will be both exciting and rewarding.

1.4Reader Audience

We are writing to an audience of Java programmers. If you're reading this book, then you're interested in enterprise computing. A complete enterprise application entails many parts: one or more clients, an application server to manage the EJBs you write and deploy, and a Java Virtual Machine (JVM) to execute Java bytecode. Clients come in many flavors: a command-line Java program, a Java Server Pages (JSP) web component, or even a client that uses Java's Swing GUI are all common types of clients. Some familiarity with database software is helpful. Java Database Connectivity (JDBC) is the Java API for portable database operations. While we don't assume you know JSP or JDBC, we do provide only an overview of these subjects-enough so that you can follow and understand our examples.

We take a similar approach with our overviews of the Java Message Service (JMS) and the EJB Query Language (EJB QL). JMS underlies the implementation of message-driven beans. Bean developers use EJB QL to compose custom queries for CMP entity beans.

1.5About the Examples

Enterprise JavaBeans Component Architecture is an example-driven book. Our goal is to show you how to design effective EJB components through our examples. Each example teaches you some aspect of EJB design. For instance, our first example (Loan EJB) illustrates the design and use of a stateless session bean (see "The Loan Enterprise Bean" on page 36).

The enterprise computing community has developed a rich set of design patterns. Where possible, we apply accepted design patterns within our examples, explaining the benefit that each pattern brings, as well as presenting its complete implementation. See, for example, the Session Facade Pattern implemented in several examples ("Session Facade Pattern" on page 250 as well as "Session Facade Pattern" on page 329).

We've attempted to bring an element of real-world problem solving to our program examples. At the same time, we avoid solutions that entail layers and layers of abstraction. We hope the developer can recognize the types of enterprise applications our examples represent and use our code as a starting point for further development. For example, we've written a JSP web component client that allows a user to log into a "system" based on a user name and a password. An underlying database stores "customer data," and several enterprise Java beans provide the database lookup and verification steps. There's hardly a customer-based web site that doesn't need a similar capability (see "Web Component Client" on page 262).

Note that besides presenting code for all our EJB examples, we also present complete code for the clients. It may be surprising to see JSP programs in a book about EJB, but our belief is that the examples become more useful when you see how they work within a complete application. Also, an EJB is a component-and components can have all sorts of clients. Thus, we show you a JSP client and a stand-alone Java client with the same EJB.

We've developed and deployed all our examples using the Sun Microsystems Reference Implementation. We run the J2EE server on a Solaris Machine, but have tested our clients on several platforms including Windows and Red Hat Linux.

1.6Source Code Online

We maintain all the source code in this book at an FTP site. You can reach this site through our web site at http://www.asgteach.com


Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020