Enterprise JavaBeans, 3.0 By Bill Burke, Richard Monson-Haefel Publisher: O'Reilly Pub Date: May 16, 2006 Print ISBN-10: 0-596-00978-X Pages: 760 Table of Contents | Index Enterprise JavaBeans, 3.0 By Bill Burke, Richard Monson-Haefel Publisher: O'Reilly Pub Date: May 16, 2006 Print ISBN-10: 0-596-00978-X Pages: 760 Table of Contents | Index Copyright Dedication Foreword Preface Part PART I: The EJB 3.0 Standard Chapter 1 Introduction Section 1.1 Server-Side Components Section 1.2 Persistence and Entity Beans Section 1.3 Asynchronous Messaging Section 1.4 Web Services Section 1.5 Titan Cruises: An Imaginary Business Section 1.6 What's Next? Chapter 2 Architectural Overview Section 2.1 The Entity Bean Section 2.2 The Enterprise Bean Component Section 2.3 Using Enterprise and Entity Beans Section 2.4 The Bean-Container Contract Section 2.5 Summary Chapter 3 Resource Management and Primary Services Section 3.1 Resource Management Section 3.2 Primary Services Section 3.3 What's Next? Chapter 4 Developing Your First Beans Section 4.1 Developing an Entity Bean Section 4.2 Developing a Session Bean Chapter 5 Persistence: EntityManager Section 5.1 Entities Are POJOs Section 5.2 Managed Versus Unmanaged Entities Section 5.3 Packaging a Persistence Unit Section 5.4 Obtaining an EntityManager Section 5.5 Interacting with an EntityManager Section 5.6 Resource Local Transactions Chapter 6 Mapping Persistent Objects Section 6.1 The Programming Model Section 6.2 Basic Relational Mapping Section 6.3 Primary Keys Section 6.4 Property Mappings Section 6.5 Multitable Mappings with @SecondaryTable Section 6.6 @Embedded Objects Chapter 7 Entity Relationships Section 7.1 The Seven Relationship Types Section 7.2 Mapping Collection-Based Relationships Section 7.3 Detached Entities and FetchType Section 7.4 Cascading Chapter 8 Entity Inheritance Section 8.1 Single Table per Class Hierarchy Section 8.2 Table per Concrete Class Section 8.3 Table per Subclass Section 8.4 Mixing Strategies Section 8.5 Nonentity Base Classes Chapter 9 Queries and EJB QL Section 9.1 Query API Section 9.2 EJB QL Section 9.3 Native Queries Section 9.4 Named Queries Chapter 10 Entity Callbacks and Listeners Section 10.1 Callback Events Section 10.2 Callbacks on Entity Classes Section 10.3 Entity Listeners Chapter 11 Session Beans Section 11.1 The Stateless Session Bean Section 11.2 SessionContext Section 11.3 The Life Cycle of a Stateless Session Bean Section 11.4 The Stateful Session Bean Section 11.5 The Life Cycle of a Stateful Session Bean Section 11.6 Stateful Session Beans and Extended Persistence Contexts Section 11.7 Nested Stateful Session Beans Chapter 12 Message-Driven Beans Section 12.1 JMS and Message-Driven Beans Section 12.2 JMS-Based Message-Driven Beans Section 12.3 The Life Cycle of a Message-Driven Bean Section 12.4 Connector-Based Message-Driven Beans Section 12.5 Message Linking Chapter 13 Timer Service Section 13.1 Titan's Maintenance Timer Section 13.2 Timer Service API Section 13.3 Transactions Section 13.4 Stateless Session Bean Timers Section 13.5 Message-Driven Bean Timers Section 13.6 Final Words Chapter 14 The JNDI ENC and Injection Section 14.1 The JNDI ENC Section 14.2 Reference and Injection Types Chapter 15 Interceptors Section 15.1 Intercepting Methods Section 15.2 Interceptors and Injection Section 15.3 Intercepting Life Cycle Events Section 15.4 Exception Handling Section 15.5 Interceptor Life Cycle Section 15.6 Bean Class @AroundInvoke Methods Section 15.7 Future Interceptor Improvements Chapter 16 Transactions Section 16.1 ACID Transactions Section 16.2 Declarative Transaction Management Section 16.3 Isolation and Database Locking Section 16.4 Nontransactional EJBs Section 16.5 Explicit Transaction Management Section 16.6 Exceptions and Transactions Section 16.7 Transactional Stateful Session Beans Section 16.8 Conversational Persistence Contexts Chapter 17 Security Section 17.1 Authentication and Identity Section 17.2 Authorization Section 17.3 The RunAs Security Identity Section 17.4 Programmatic Security Chapter 18 EJB 3.0: Web Services Standards Section 18.1 Web Services Overview Section 18.2 XML Schema and XML Namespaces Section 18.3 SOAP 1.1 Section 18.4 WSDL 1.1 Section 18.5 UDDI 2.0 Section 18.6 From Standards to Implementation Chapter 19 EJB 3.0 and Web Services Section 19.1 Accessing Web Services with JAX-RPC Section 19.2 Defining a Web Service with JAX-RPC Section 19.3 Using JAX-WS Section 19.4 Other Annotations and APIs Chapter 20 Java EE Section 20.1 Servlets Section 20.2 JavaServer Pages Section 20.3 Web Components and EJB Section 20.4 Filling in the Gaps Section 20.5 Fitting the Pieces Together Chapter 21 EJB Design in the Real World Section 21.1 Predesign: Containers and Databases Section 21.2 Design Section 21.3 Should You Use EJBs? Section 21.4 Wrapping Up Part PART II: The JBoss Workbook Introduction Section 22.1 Contents of the JBoss Workbook Chapter WORKBOOK 1 JBoss Installation and Configuration Section 23.1 About JBoss Section 23.2 Installing the JBoss Application Server Section 23.3 A Quick Look at JBoss Internals Section 23.4 Exercise Code Setup and Configuration Chapter WORKBOOK 2 Exercises for Chapter 4 Section 24.1 Exercise 4.1: Your First Beans with JBoss Section 24.2 Exercise 4.2: JNDI Binding with Annotations Section 24.3 Exercise 4.3: JNDI Binding with XML Chapter WORKBOOK 3 Exercises for Chapter 5 Section 25.1 Exercise 5.1: Interacting with EntityManager Section 25.2 Exercise 5.2: Standalone Persistence Chapter WORKBOOK 4 Exercises for Chapter 6 Section 26.1 Exercise 6.1: Basic Property Mappings Section 26.2 Exercise 6.2: @IdClass Section 26.3 Exercise 6.3: @EmbeddedId Section 26.4 Exercise 6.4: Multitable Mappings Section 26.5 Exercise 6.5: Embeddable Classes Chapter WORKBOOK 5 Exercises for Chapter 7 Section 27.1 Exercise 7.1: Cascading Section 27.2 Exercise 7.2: Inverse Relationships Section 27.3 Exercise 7.3: Lazy Initialization Chapter WORKBOOK 6 Exercises for Chapter 8 Section 28.1 Exercise 8.1: Single Table per Hierarchy Section 28.2 Exercise 8.2: Single Table per Hierarchy Section 28.3 Exercise 8.3: JOINED Inheritance Strategy Chapter WORKBOOK 7 Exercises for Chapter 9 Section 29.1 Exercise 9.1: Query and EJB QL Basics Chapter WORKBOOK 8 Exercises for Chapter 10 Section 30.1 Exercise 10.1: Entity Callbacks Section 30.2 Exercise 10.2: Entity Listeners Chapter WORKBOOK 9 Exercises for Chapter 11 Section 31.1 Exercise 11.1: Stateless Session Bean Section 31.2 Exercise 11.2: XML Override Section 31.3 Exercise 11.3: Annotationless Stateless Session Bean Section 31.4 Exercise 11.4: Stateful Session Bean Section 31.5 Exercise 11.5: Annotationless Stateful Session Bean Chapter WORKBOOK 10 Exercises for Chapter 12 Section 32.1 Exercise 12.1: The Message-Driven Bean Chapter WORKBOOK 11 Exercises for Chapter 13 Section 33.1 Exercise 13.1: EJB Timer Service Chapter WORKBOOK 12 Exercises for Chapter 15 Section 34.1 Exercise 15.1: EJB Interceptors Section 34.2 Exercise 15.2: Intercepting EJB Callbacks Chapter WORKBOOK 13 Exercises for Chapter 16 Section 35.1 Exercise 16.1: Conversational Persistence Contexts Chapter WORKBOOK 14 Exercises for Chapter 17 Section 36.1 Exercise 17.1: Security Section 36.2 Exercise 17.2: Securing Through XML Chapter WORKBOOK 15 Exercises for Chapter 19 Section 37.1 Exercise 19.1: Exposing a Stateless Bean Section 37.2 Exercise 19.2: Using a NET Client Part PART III: Appendix JBoss Database Configuration Section A.1 Set Up the Database Section A.2 Examine the persistence.xml File Section A.3 Start Up JBoss Section A.4 Build and Deploy the Example Programs Section A.5 Examine and Run the Client Applications About the Authors Colophon Index Enterprise JavaBeans™ 3.0, Fifth Edition by Bill Burke and Richard Monson-Haefel Copyright © 2006, 2004, 2001, 2000, 1999 O'Reilly Media, Inc 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 (safari.oreilly.com) For more information, contact our corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com Editor: Mike Loukides Production Editor: Colleen Gorman Copyeditor: Audrey Doyle Proofreaders: Matt Hutchinson and Rachel Monaghan Indexer: Julie Hawks Cover Designer: Hanna Dyer Interior Designer: David Futato Illustrators: Robert Romano and Jessamyn Read Printing History: June 1999: First Edition March 2000: Second Edition September 2001: Third Edition June 2004: Fourth Edition May 2006: Fifth Edition Nutshell Handbook, the Nutshell Handbook logo, and the O'Reilly logo are registered trademarks of O'Reilly Media, Inc Enterprise JavaBeans™, Fifth Edition, the image of a wallaby and joey, and related trade dress are trademarks of O'Reilly Media, Inc Java™ and all Java-based trademarks and logos are trademarks or registered trademarks of Sun Microsystems, Inc., in the United States and other countries O'Reilly Media, Inc is independent of Sun Microsystems Microsoft, Windows, Windows NT, and the Windows logo are trademarks or registered trademarks of Microsoft Corporation in the United States and other countries JBoss is fully owned and operated by JBoss, Inc in the United States and other countries 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 contained herein ISBN: 0-596-00978-X [M] Never NotSupported persistence and Required RequiresNew Supports business business systems that employ consistent conversational persistence contexts declarative transaction management @javax.ejb.TransactionAttribute durable exceptions and application exceptions system exceptions explicit transaction management bean-managed transations EJBContext rollback methods heuristic decisions UserTransaction interface isolated isolation and database locking balancing performance against consistency dirty read dirty reads exclusive write locks isolation levels nonrepeatable read optimistic locking phantom read phantom reads programmatic locking read locks repeatable read repeatable reads snapshots write locks JTA nontransactional EJBs propogation persistence context propagation rollbacks two-phase commit (2-PC or TPC) scope 2nd stateful session beans suspended versus extended persistence transations distributed resource local @Transient 2nd 3rd element TravelAgent 2nd 3rd 4th TravelAgent EJB annotation injection atomic characteristics bean class bookPassage( ) method 2nd 3rd client view consistent characteristics durable characteristics getting set up for isolated characteristics local interface reference to ProcessPayment EJB purpose of remote interface TicketDO class with JMS XML deployment descriptor TravelAgent.bookPassage( ) method travelagent_mapping.xml file TravelAgentBean bean class code sample complete definition developing ENC reference 2nd exposing JNDI lookups looking up EntityManagerFactory lookup EntityManager partial definition for new setPayment( ) method source code TravelAgentBean class getting access to EntityManager TravelAgentBean.bookPassage( ) method 2nd TravelAgentBean.checkout( ) method TravelAgentBean.flushmodeExample( ) method TravelAgentBean.updateAddress( ) method TravelAgentBean.updateCabin( ) method TravelAgentLocal interface TravelAgentRemote 2nd 3rd 4th 5th 6th 7th developing findCabin( ) method getting remote reference to TravelAgentRemote interface TravelAgentRemote.bookPassage( ) method TravelAgentService 2nd TravelAgentShell TravelAgentShell application 2nd 3rd 4th 5th 6th 7th TravelAgentWS interface TRIM TRIM( ) try/catch blocks 2nd 3rd 4th two-phase commit (2-PC or TPC) two-phase commit (2-PC) type attribute type( ) attribute 2nd type( ) method 2nd 3rd 4th 5th 6th 7th element 2nd 3rd Index [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Z] UDDI 2.0 unbounded element UNION unique( ) method element @UniqueConstraint UniqueConstraint[] uniqueConstraints( ) method unit-of-work unitName( ) attribute unitName( ) method 2nd 3rd 4th 5th 6th 7th 8th UNKNOWN 2nd 3rd UNREGISTERED updatable( ) method 2nd UPDATE 2nd 3rd UPDATE operation updateAddress( ) method 2nd updateBedCount( ) method 2nd 3rd updateBeds( ) method updateCabin( ) method 2nd 3rd 4th updateCruise updateReservation( ) method 2nd 3rd updateShip updating entities UPPER UPPER( ) USB-compliant devices use( ) method element element users-titan.properties file usersProperties UserTransaction interface begin( ) method commit( ) method getStatus( ) method rollback( ) method setRollbackOnly( ) method setTransactionTimeout( ) method STATUS_ACTIVE STATUS_COMMITTED STATUS_COMMITTING STATUS_MARKED_ROLLBACK STATUS_NO_TRANSACTION STATUS_PREPARED STATUS_PREPARING STATUS_ROLLEDBACK STATUS_ROLLING_BACK STATUS_UNKNOWN UserTransaction.begin( ) method 2nd UserTransaction.commit( ) method 2nd UserTransaction.setRollbackOnly( ) method UsingDistinct application utility classes design utx Index [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Z] valid validateCheck( ) method Value Object Pattern value( ) attribute 2nd value( ) method 2nd 3rd VALUE_COLUMN valueColumnName( ) method VARCHAR 2nd 3rd @Version 2nd version 2nd void 2nd 3rd 4th 5th 6th Index [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Z] war file war files (web component JAR files) wburke 2nd web archive web component JAR files (.war files) web components filling gaps between Enterprise JavaBeans and Web Service Description Language (WSDL) web service references @javax.xml.ws.WebServiceRef XML-based resource references web services overview SOAP 1.1 WSDL 1.1 web services contract Web Services for Java EE (WS-Java EE) web services in EJB 3.0 web services messaging Web Services Metadata for Java EE WebLogic @WebMethod @WebParam 2nd @WebResult 2nd @WebService element element @WebServiceRef webservices.xml file 2nd well formed WHERE clause 2nd 3rd 4th 5th arithmetic operators BETWEEN comparison symbols equality semantics IN operator IS EMPTY IS NULL LIKE literals logical operators MEMBER OF operator precedence WHERE clause and literals (EJB QL) WhereIn application withdraw( ) method workbook Ant script environment setup contents downloading example code for exercises exercise directory structure exercises overview Hypersonic SQL JBoss installation and configuration installing server internals JBoss database configuration workflow applications workflow scheduling examples write locks exclusive WS-I (Web Services Integration Organization) WS-I Basic Profile 1.1 WS-Java EE WSDL (Web Service Description Language) 2nd WSDL 1.1 2nd element element element element element element WSDL document WSDL document for Charge-It's web service element 2nd 3rd 4th element named method declarations element wsdl:part 2nd wsdlLocation( ) attribute 2nd 3rd Index [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Z] XML documents and correctness injection mapping file markup language securing through XML deployment descriptors 2nd 3rd 4th 5th 6th environment entities and Java EE and jboss.xml orm.xml TravelAgent EJB XML namespaces default 2nd prefix XML Schema 2nd built-in types built-in types and their corresponding Java type declaring elements of XSD built-in types parser types, mapping XML documents and correctness xsd:base64Binary xsd:Boolean xsd:byte xsd:dateTime 2nd xsd:decimal xsd:double xsd:float xsd:hexBinary xsd:int 2nd 3rd xsd:integer xsd:long xsd:QName xsd:short xsd:string 2nd 3rd Index [A] [B] [C] [D] [E] [F] [G] [H] [I] [J] [K] [L] [M] [N] [O] [P] [Q] [R] [S] [T] [U] [V] [W] [X] [Z] Zip code zip property ... Robert Romano and Jessamyn Read Printing History: June 1999: First Edition March 200 0: Second Edition September 200 1: Third Edition June 200 4: Fourth Edition May 200 6: Fifth Edition Nutshell Handbook, the Nutshell Handbook logo, and the... Examine and Run the Client Applications About the Authors Colophon Index Enterprise JavaBeans 3. 0, Fifth Edition by Bill Burke and Richard Monson-Haefel Copyright © 200 6, 200 4, 200 1, 200 0, 1999 O'Reilly Media, Inc All rights reserved.. .Enterprise JavaBeans, 3. 0 By Bill Burke, Richard Monson-Haefel Publisher: O'Reilly Pub Date: May 16, 200 6 Print ISBN- 10: 0- 596 -00 978-X Pages: 7 60 Table of Contents | Index