CHAPTER 1 INTRODUCTION TO THE EJB ARCHITECTURE Chapter 3:Entities and the Java Persistence API The Java Persistence API(JPA)is introduced,along with the various persistence services that are available to support entities both within a Java EE container and outside of one.This chapter covers basicO/R mappings,and it introduces the Java Persistence Query Language,or JPQL. Chapter 4:Advanced Persistence Features Delving into more advanced persistence concepts,this chapter describes the support offered in IPA for mapping entity inheritance hierarchies.Examples of the three supported inheritance mapping strategies identify the strengths and weaknesses of each approach in order to help you decide which one best suits the particular needs of your application.Among other topics,this chapter als so covers complex p imary key(PK)mappings,ID generators for autopopulating primary key values using a database sequence or table,locking strategies and cache management Chapter 5:EJB Message-Driven Beans ous,event-driven behavior to your application 'smessaging APl,is explained and demonstrated in this chapter's code examples. Chapter 6:EJB and Web Services Chapter 7:Integrating Session Beans,Entities,Message-Driven Beans, and Web Services After covering all of the different com oonent model types individually.Chapter 7 brings them all together in an ee how everythingfits together to Chapter 8:Transaction Support in EJB EJB offers rich transaction service support,and it makes it easy for Bean Providers to declaratively specify custom container-provided transactional behavior on an enterprise bean.EJB also allows enterprise beans to opt out of this model,and control their own transaction demarcation behavior.This chapter applies two alternative transactional models to a single logical scenario for weighing the benefits of each approach. Chapter 9:EJB Performance and Testing This chapter provides an invaluable look at how to gauge the performance of your EJB components in order to help you decide which of the many options EJB offers is right for your application.In addition to explaining how to set up performance tests,we present some performance test cases that we have run,complete with our assessments of the results
Chapter 1 ■ IntroduCtIon to the eJB arChIteCture 9 Chapter 3: Entities and the Java Persistence API The Java Persistence API (JPA) is introduced, along with the various persistence services that are available to support entities both within a Java EE container and outside of one. This chapter covers basic O/R mappings, and it introduces the Java Persistence Query Language, or JPQL. Chapter 4: Advanced Persistence Features Delving into more advanced persistence concepts, this chapter describes the support offered in JPA for mapping entity inheritance hierarchies. Examples of the three supported inheritance mapping strategies identify the strengths and weaknesses of each approach in order to help you decide which one best suits the particular needs of your application. Among other topics, this chapter also covers complex primary key (PK) mappings, ID generators for autopopulating primary key values using a database sequence or table, locking strategies and cache management. Chapter 5: EJB Message-Driven Beans This chapter describes how you can use MDBs to add asynchronous, event-driven behavior to your application. JMS, Java’s messaging API, is explained and demonstrated in this chapter’s code examples. Chapter 6: EJB and Web Services Session beans provide an excellent implementation for Web Services, and this chapter explores EJB’s support for this fine marriage of technologies. Chapter 7: Integrating Session Beans, Entities, Message-Driven Beans, and Web Services After covering all of the different component model types individually, Chapter 7 brings them all together in an integrated Java EE application. We think you will find it particularly useful to see how everything fits together to produce a running application. Chapter 8: Transaction Support in EJB EJB offers rich transaction service support, and it makes it easy for Bean Providers to declaratively specify custom container-provided transactional behavior on an enterprise bean. EJB also allows enterprise beans to opt out of this model, and control their own transaction demarcation behavior. This chapter applies two alternative transactional models to a single logical scenario for weighing the benefits of each approach. Chapter 9: EJB Performance and Testing This chapter provides an invaluable look at how to gauge the performance of your EJB components in order to help you decide which of the many options EJB offers is right for your application. In addition to explaining how to set up performance tests, we present some performance test cases that we have run, complete with our assessments of the results
CHAPTER 1 INTRODUCTION TO THE EJB ARCHITECTURE Chapter 10:Contexts and Dependency Injection n a pow erfu s ofinjecting resou e are cont support emna8edb ser an applic Chapter 11:EJB Packaging and Deployment oieomsaaeolednilohisch n Ass ways into an enterprise archive (EAR)file. esolving s between modules and between ElBs packaged into erent modules,and binding re ource r nts to con crete ces installed in the arget a erve environment Chapter 12:EJB Client Applications In this chapter.we walk you through application architectures and different programming models that you can use to build applications,including the pros and cons of each approach.Once we have done that,we settle on one application architecture-developing Web applications using JavaServer Faces(JSF)technology.We then drill down into the JSF architecture and concepts,and focus on integrating JSF user interface components and the JSF navigation model with the EJB/WebService/IPA back-end application that we developed in Chapter 7. Finally,we also explain how to use a lightweight application client container to execute your session beans in a pure Java SE environment.This lightweight container provides EJBs that execute in its environment with some of the services (such as container injection)that are offered by a true EJB container. Chapter 13:Testing in an Embeddable EJB Container naproduction server nts within a lightv eight subset of the EJB Container,known as EJ Lite and implemer a pur Thi GlaFish's Er s and guides you in using JUnit to test EJB components(and JPA entities)in Getting Started This section of the chapter will ge you ready with the software installation and configuration required to work with the samples in the rest of the book.At the time of this writing the EJB 3.2 specification was on its way to being finalized.The GlassFish application server had implemented the specification that allowed the developer community to get hands-on experience with the new specification. GlassFish is an open source application server that implements the newest features of the Java EE platform. In fact,GlassFish is the reference implementation for all of the specifications of the Java EE platform,including the EJB 3.2 specification.Glassfish releases are tracked closely by the NetBeans IDE,ensuring that NetBeans supports the very Beans the ideal platform for deploying and running the example in this book.Y ins application project compris one or more ad I projects represe ng the EJE other mod onstrate the apte e sa is are a o run in th a Fish server,th (by virtue of fol s and may be deployed to the Java 7 server oryour ch eportabl 10
Chapter 1 ■ Introduction to the EJB Architecture 10 Chapter 10: Contexts and Dependency Injection Introduced in Java EE 6, Contexts and Dependency Injection (CDI) services augment the component model defined in EJB with a powerful means of injecting resources into your application whose life cycles are contextual and conveniently managed by the server. This chapter introduces CDI and explains how EJB developers can leverage this support to enrich an application’s behavior. Chapter 11: EJB Packaging and Deployment Assembly and deployment are rolled into this chapter, as we cover the tasks required of the Application Assembler and Deployer roles. This chapter discusses packaging EJB and persistence modules, assembling modules in different ways into an enterprise archive (EAR) file, resolving references between modules and between EJBs packaged into different modules, and binding resource requirements to concrete resources installed in the target application server environment. Chapter 12: EJB Client Applications In this chapter, we walk you through application architectures and different programming models that you can use to build applications, including the pros and cons of each approach. Once we have done that, we settle on one application architecture—developing Web applications using JavaServer Faces (JSF) technology. We then drill down into the JSF architecture and concepts, and focus on integrating JSF user interface components and the JSF navigation model with the EJB/WebService/JPA back-end application that we developed in Chapter 7. Finally, we also explain how to use a lightweight application client container to execute your session beans in a pure Java SE environment. This lightweight container provides EJBs that execute in its environment with some of the services (such as container injection) that are offered by a true EJB container. Chapter 13: Testing in an Embeddable EJB Container In a production deployment EJB components run in a Java EE environment, inside an application server. For testing purposes, EJB allows you to test your EJB components within a lightweight subset of the EJB Container, known as EJB Lite and implemented as an Embeddable EJB Container, that can run in a pure Java SE environment. This chapter covers a variety of EJB testing scenarios and guides you in using JUnit to test EJB components (and JPA entities) in GlassFish’s Embeddable EJB Container. Getting Started This section of the chapter will get you ready with the software installation and configuration required to work with the samples in the rest of the book. At the time of this writing, the EJB 3.2 specification was on its way to being finalized. The GlassFish application server had implemented the specification that allowed the developer community to get hands-on experience with the new specification. GlassFish is an open source application server that implements the newest features of the Java EE platform. In fact, GlassFish is the reference implementation for all of the specifications of the Java EE platform, including the EJB 3.2 specification. Glassfish releases are tracked closely by the NetBeans IDE, ensuring that NetBeans supports the very latest state of the Java EE specifications and making NetBeans the ideal platform for deploying and running the examples in this book. You will find that each successive chapter is accompanied by a NetBeans application project comprised of one or more additional projects representing the EJB, Web, or other modules that demonstrate the features covered in that chapter. Although these sample applications are all configured to run in the GlassFish server, they are portable (by virtue of following the Java EE standards) and may be deployed to the Java EE 7 server of your choice
CHAPTER 1 INTRODUCTION TO THE EJB ARCHITECTURE Although we built and tested the examples in this book using netbeans in a windows 7 environment.the code samples are not operating system specific,and they can be executed on any ht have to tweak the envi Note You can find more details on the NetBeans IDE and its integrated GlassFish application server at the following website:http://netbeans.org/features/index.html. The remaining sections of this chapter will cover the following Downloading the NetBeans IDE Installing NetBeans and its integrated GlassFish server Testing NetBeans and GlassFish installation Administrating the GlassFish application server Even if you are familiar with NetBeans and GlassFish,we recommend that you read through the following sections,as running the sample code in the rest of the chapters depends on this setup being done correctly. Downloading the NetBeans IDE You can download the latest NetBeans installer from the following location: http://netbeans.org/downloads/ u download the installer with"Java EE"technolo as shown in Figure 1-1.This installer will also contain the SE and GlassFish can use it o configure the envin 11
Chapter 1 ■ Introduction to the EJB Architecture 11 Although we built and tested the examples in this book using NetBeans in a Windows 7 environment, the code samples are not operating system specific, and they can be executed on any system that can run NetBeans and its integrated GlassFish server. Nevertheless, you might have to tweak the environment settings to install and execute NetBeans and its integrated GlassFish server on other operating systems. ■ Note You can find more details on the NetBeans IDE and its integrated GlassFish application server at the following website: http://netbeans.org/features/index.html. The remaining sections of this chapter will cover the following: • Downloading the NetBeans IDE • Installing NetBeans and its integrated GlassFish server • Testing NetBeans and GlassFish installation • Administrating the GlassFish application server Even if you are familiar with NetBeans and GlassFish, we recommend that you read through the following sections, as running the sample code in the rest of the chapters depends on this setup being done correctly. Downloading the NetBeans IDE You can download the latest NetBeans installer from the following location: http://netbeans.org/downloads/ Make sure that you download the installer with “Java EE” technology, as shown in Figure 1-1. This installer will also contain the required Java SE and GlassFish packages. Ant is included with GlassFish; you can either use it or configure the environment properties to use another installation. The GlassFish project recommends that you use Ant, which is bundled with its install
CHAPTER 1 INTRODUCTION TO THE EJB ARCHITECTURE 沙图g。·台口 NetBeans IDE 7.3 Download C e To Figure 1-1.Downloading the NetBeans IDE Note When we started writing this book,the latest NetBeans version was 7.2.During the process of writing it, version 7.3 was released.We have tested the setup and the sample code using the NetBeans 7.3 version. Once the download is complete,you are set to start the installation of NetBeans along with its integrated GlassFish server. Installing NetBeans IDE and Its Integrated GlassFish Server Navigate to the directory where the NetBeans IDE installer has been downloaded,and run the installer.The first page of the installer wizard lists the packages that will be installed.If you see the"No compatible JDK was found"warning b3anteaing2hheaounlhaneoeiewiandandistowmioadandnalhahaihm http://www.oracle.com/technetwork/java/javase/downloads/index.html 12
Chapter 1 ■ Introduction to the EJB Architecture 12 ■ Note When we started writing this book, the latest NetBeans version was 7.2. During the process of writing it, version 7.3 was released. We have tested the setup and the sample code using the NetBeans 7.3 version. Once the download is complete, you are set to start the installation of NetBeans along with its integrated GlassFish server. Installing NetBeans IDE and Its Integrated GlassFish Server Navigate to the directory where the NetBeans IDE installer has been downloaded, and run the installer. The first page of the installer wizard lists the packages that will be installed. If you see the “No compatible JDK was found” warning message, as shown in Figure 1-2, then you will have to exit the wizard and first download and install Java Platform (JDK) 7 from the following location. http://www.oracle.com/technetwork/java/javase/downloads/index.html Figure 1-1. Downloading the NetBeans IDE
CHAPTER 1 INTRODUCTION TO THE EJB ARCHITECTURE NetBeans IDE Installer Welome to the NetBeans IDE 7.3 Installer Select the applicaion servers to install with the DE: 图NetBeans0E Installaton Size:537.MB No compatible DK was found. Next Cancel Figure 1-2.Installing NetBeans."No compatible DK was found"warning Note Even if you don't see the"No compatible DK was found"warning,verify that you have Java Platform (JDK)7 installed.If you don't have the Java Platform(JDK)7 installed,then you might get a"javac:invalid target release:1.7"error while executing the samples in this book. Rerun the NetBeans installer afera.Verify that the"K found"warning does not the rd ke gall of the default values sel 3
Chapter 1 ■ Introduction to the EJB Architecture 13 Figure 1-2. Installing NetBeans. “No compatible JDK was found” warning ■ Note Even if you don’t see the "No compatible JDK was found" warning, verify that you have Java Platform (JDK) 7 installed. If you don’t have the Java Platform (JDK) 7 installed, then you might get a "javac: invalid target release: 1.7" error while executing the samples in this book. Rerun the NetBeans installer after a compatible JDK version is installed. Verify that the “No compatible JDK found” warning does not reoccur, and traverse the wizard, keeping all of the default values selected. The “Summary” page will list the folders where the NetBeans IDE and the GlassFish application server will be installed. Finish the wizard by pressing the Install button, as shown in Figure 1-3