EJB3 IN ACTION Debu Panda Reza Rahman Derek Lane MANNING
brief contents PART 1 OVERVIEW OF THE EJB LANDSCAPE...................... 1·What's what in EJB33 2.A first taste of EJB 33 PART 2 BUILDING BUSINESS LOGIC WITH EJB 3 .........69 3.Building business logic with session beans 71 4.Messaging and developing MDBs 110 5 Learning advanced EJB concepts 140 6.Transactions and security 176 PART 3 DIVING INTO THE JAVA PERSISTENCE API (JPA)215 7.Implementing domain models 217 8.Object-relational mapping 250 9.Manipulating entities with Entity Manager 293 10.Using the query API and JPQL to retrieve entities 340
vii PART 1 OVERVIEW OF THE EJB LANDSCAPE ........................ 1 1 ■ What’s what in EJB 3 3 2 ■ A first taste of EJB 33 PART 2 BUILDING BUSINESS LOGIC WITH EJB 3 .............. 69 3 ■ Building business logic with session beans 71 4 ■ Messaging and developing MDBs 110 5 ■ Learning advanced EJB concepts 140 6 ■ Transactions and security 176 PART 3 DIVING INTO THE JAVA PERSISTENCE API (JPA) 215 7 ■ Implementing domain models 217 8 ■ Object-relational mapping 250 9 ■ Manipulating entities with EntityManager 293 10 ■ Using the query API and JPQL to retrieve entities 340 brief contents
BRIEF CONTENTS PART 4 PUTTING EJB 3 INTO ACTION.385 11.Packaging EJB 3 applications 387 12 Effectively integrating EJB3across your application tiers 425 13.Taming wild EJBs:performance and scalability 455 PART 5 MIGRATION AND INTEROPERABILITY ISSUES ....497 14.Migrating to EJB 3 499 15 Exposing EJBs as web services 537 16·EJB3 and Spring568
viii BRIEF CONTENTS PART 4 PUTTING EJB 3 INTO ACTION ............................ 385 11 ■ Packaging EJB 3 applications 387 12 ■ Effectively integrating EJB 3 across your application tiers 425 13 ■ Taming wild EJBs: performance and scalability 455 PART 5 MIGRATION AND INTEROPERABILITY ISSUES ..... 497 14 ■ Migrating to EJB 3 499 15 ■ Exposing EJBs as web services 537 16 ■ EJB 3 and Spring 568
contents preface xix acknowledgments xxi about this book xxiv PART 1 OVERVIEW OF THE EIB LANDSCAPE........................... What's what in EJB 3 3 1.1 EJB overview 5 EJB as a component 5"E[B as a framework 7 Layered architectures and EJB 9.Why choose EJB 3?12 1.2 Understanding EJB types 14 Session beans 16.Message-driven beans 16.Entities and the Java Persistence API 17 1.3 Getting inside EJB 19 Accessing E[B services:the E[B container 20.Accessing PA services:the persistence provider 20.Gaining functionality with EJB services 21 ix
ix preface xix acknowledgments xxi about this book xxiv PART 1 OVERVIEW OF THE EJB LANDSCAPE .......................... 1 1 What’s what in EJB 3 3 1.1 EJB overview 5 EJB as a component 5 ■ EJB as a framework 7 Layered architectures and EJB 9 ■ Why choose EJB 3? 12 1.2 Understanding EJB types 14 Session beans 16 ■ Message-driven beans 16 ■ Entities and the Java Persistence API 17 1.3 Getting inside EJB 19 Accessing EJB services: the EJB container 20 ■ Accessing JPA services: the persistence provider 20 ■ Gaining functionality with EJB services 21 contents
CONTENTS 1.4 Renaissance of EJB 23 d of depl POJO components 29.EJB 5 and Spring 50 1.5 Summary 32 A first taste of EJB 33 2.1 New features:simplifying EJB 35 ing dependency injection 40 2.2 Introducing the ActionBazaar application 41 Starting with the architecture 42.An E[B 3-based solution 43 2.3 Building business logic with session beans 45 Using stateless beans 45The stateless bean client 47 Using stateful beans 50"A stateful bean client 54 2.4 Messaging with message-driven beans 56 Producing a billing message 57.Using the order billing message processor MDB 59 2.5 Persisting data with EJB 3 JPA 61 2.6 Summary 67 PART 2 BUILDING BUSINESS LOGIC WTTH EJB 3..................69 3 Building business logic with session beans 71 3.1 Getting to know session beans 72 Why use session beans?73.Session beans:the basics 75 Understanding the programming rules 78.Conversational state and session bean types 79.Bean lifecycle callbacks 79 3.2 Stateless session beans 83 The BidManagerBean example 84.Using
x CONTENTS 1.4 Renaissance of EJB 23 HelloUser Example 24 ■ Simplified programming model 25 ■ Annotations instead of deployment descriptors 26 ■ Dependency injection vs. JNDI lookup 27 ■ Simplified persistence API 27 ■ Unit-testable POJO components 29 ■ EJB 3 and Spring 30 1.5 Summary 32 2 A first taste of EJB 33 2.1 New features: simplifying EJB 35 Replacing deployment descriptors with annotations 35 ■ Introducing dependency injection 40 2.2 Introducing the ActionBazaar application 41 Starting with the architecture 42 ■ An EJB 3–based solution 43 2.3 Building business logic with session beans 45 Using stateless beans 45 ■ The stateless bean client 47 Using stateful beans 50 ■ A stateful bean client 54 2.4 Messaging with message-driven beans 56 Producing a billing message 57 ■ Using the order billing message processor MDB 59 2.5 Persisting data with EJB 3 JPA 61 Working with the Java Persistence API 62 ■ Using the EntityManager 65 2.6 Summary 67 PART 2 BUILDING BUSINESS LOGIC WITH EJB 3.................. 69 3 Building business logic with session beans 71 3.1 Getting to know session beans 72 Why use session beans? 73 ■ Session beans: the basics 75 Understanding the programming rules 78 ■ Conversational state and session bean types 79 ■ Bean lifecycle callbacks 79 3.2 Stateless session beans 83 The BidManagerBean example 84 ■ Using the @Stateless annotation 86 ■ Specifying bean business interfaces 87 ■ Using bean lifecycle callbacks 90