Enterprise JavaBeans 3.1

Similar documents
Chapter 1 Introducing EJB 1. What is Java EE Introduction to EJB...5 Need of EJB...6 Types of Enterprise Beans...7

"Charting the Course... Mastering EJB 3.0 Applications. Course Summary

foreword to the first edition preface xxi acknowledgments xxiii about this book xxv about the cover illustration

Web Application Development Using JEE, Enterprise JavaBeans and JPA

object/relational persistence What is persistence? 5

Web Application Development Using JEE, Enterprise JavaBeans and JPA

Pro JPA 2. Mastering the Java Persistence API. Apress* Mike Keith and Merrick Schnicariol

Java EE 7: Back-End Server Application Development

Fast Track to EJB 3.0 and the JPA Using JBoss

Enterprise JavaBeans, Version 3 (EJB3) Programming

CO Java EE 7: Back-End Server Application Development

CO Java EE 6: Develop Database Applications with JPA

JVA-163. Enterprise JavaBeans

Java- EE Web Application Development with Enterprise JavaBeans and Web Services

Oracle - Developing Applications for the Java EE 7 Platform Ed 1 (Training On Demand)

Business Component Development with EJB Technology, Java EE 5

Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1

Deccansoft Software Services. J2EE Syllabus

SCBCD EXAM STUDY KIT. Paul Sanghera CX JAVA BUSINESS COMPONENT DEVELOPER CERTIFICATION FOR EJB MANNING. Covers all you need to pass

Java J Course Outline

Deployment. See Packaging and deployment processes

Call: JSP Spring Hibernate Webservice Course Content:35-40hours Course Outline

RESTful Java with JAX-RS

Spring & Hibernate. Knowledge of database. And basic Knowledge of web application development. Module 1: Spring Basics

Java EE 6: Develop Business Components with JMS & EJBs

Implementing a Web Service p. 110 Implementing a Web Service Client p. 114 Summary p. 117 Introduction to Entity Beans p. 119 Persistence Concepts p.

OracleAS 10g R3: Build J2EE Applications II

Spring Persistence. with Hibernate PAUL TEPPER FISHER BRIAN D. MURPHY

Practice Test. Oracle 1z Java Enterprise Edition 5 Business Component Developer Certified Professional Upgrade Exam. Version: 14.

Programming Web Services in Java

Java Enterprise Edition

Developing Applications with Java EE 6 on WebLogic Server 12c

133 July 23, :01 pm

JAVA COURSES. Empowering Innovation. DN InfoTech Pvt. Ltd. H-151, Sector 63, Noida, UP

Oracle Developer Day

Courses For Event Java Advanced Summer Training 2018

Java Programming Language

Web Application Development Using Spring, Hibernate and JPA

Java SE7 Fundamentals

Overview p. 1 Server-side Component Architectures p. 3 The Need for a Server-Side Component Architecture p. 4 Server-Side Component Architecture

BEAAquaLogic. Service Bus. Interoperability With EJB Transport

Table of Contents EJB 3.1 and JPA 2

Web Application Development Using Spring, Hibernate and JPA

Oracle TopLink. Developer s Guide, Volume 4 10g ( ) B September 2006 Understanding Non-Relational Mappings

Introduction to Web Application Development Using JEE, Frameworks, Web Services and AJAX

Web Application Development Using Spring, Hibernate and JPA

Fast Track to Java EE

Java SE 8 Fundamentals

EJB ENTERPRISE JAVA BEANS INTRODUCTION TO ENTERPRISE JAVA BEANS, JAVA'S SERVER SIDE COMPONENT TECHNOLOGY. EJB Enterprise Java

SUN. Java Platform Enterprise Edition 6 Web Services Developer Certified Professional

find() method, 178 forclass() method, 162 getcurrentsession(), 16 getexecutablecriteria() method, 162 get() method, 17, 177 getreference() method, 178

<Insert Picture Here> Productive JavaEE 5.0 Development

SERVICE-ORIENTED COMPUTING

Developing Enterprise JavaBeans for Oracle WebLogic Server 12c (12.2.1)

Skyway Builder 6.3 Reference

Borland Application Server Certification. Study Guide. Version 1.0 Copyright 2001 Borland Software Corporation. All Rights Reserved.

/ / JAVA TRAINING

Vision of J2EE. Why J2EE? Need for. J2EE Suite. J2EE Based Distributed Application Architecture Overview. Umair Javed 1

Chapter 6 Enterprise Java Beans

Web Services Development for IBM WebSphere Application Server V7.0

SUN Sun Cert Bus Component Developer Java EE Platform 5, Upgrade. Download Full Version :

Exam Questions 1Z0-895

JavaScript: The Definitive Guide

Course Content for Java J2EE

New Features in EJB 3.1

V3 EJB Test One Pager

The Java EE 6 Tutorial

ADVANCED JAVA TRAINING IN BANGALORE

these methods, remote clients can access the inventory services provided by the application.

ENTERPRISE beans are the J2EE components that implement Enterprise Java-

J2EE Development. Course Detail: Audience. Duration. Course Abstract. Course Objectives. Course Topics. Class Format.

JVA-563. Developing RESTful Services in Java

CHAPTER 1: INTRODUCING C# 3

Data Management in Application Servers. Dean Jacobs BEA Systems

Oracle EXAM - 1Z Java EE 6 Enterprise JavaBeans Developer Certified Expert Exam. Buy Full Product.

1Z Oracle. Java Enterprise Edition 5 Business Component Developer Certified Professional Upgrade

The Next Generation. Prabhat Jha Principal Engineer

Web Design and Applications

indx.qxd 11/3/04 3:34 PM Page 339 Index

Microsoft. Microsoft Visual C# Step by Step. John Sharp

Architect Exam Guide. OCM EE 6 Enterprise. (Exams IZO-807,1ZO-865 & IZO-866) Oracle Press ORACLG. Paul R* Allen and Joseph J.

Developing Enterprise JavaBeans, Version 2.1, for Oracle WebLogic Server 12c (12.1.2)

Lightweight J2EE Framework

CO Java EE 6: Develop Web Services with JAX-WS & JAX-RS

Contents at a Glance

"Charting the Course... Agile Database Design Techniques Course Summary

Index. setmaxresults() method, 169 sorting, 170 SQL DISTINCT query, 171 uniqueresult() method, 169

Java Performance: The Definitive Guide

1Z Java SE 5 and 6, Certified Associate Exam Summary Syllabus Questions

Oracle Service Bus. Interoperability with EJB Transport 10g Release 3 (10.3) October 2008

Lightweight J2EE Framework

NetBeans IDE Field Guide

Java EE Application Assembly & Deployment Packaging Applications, Java EE modules. Model View Controller (MVC)2 Architecture & Packaging EJB Module

POJOs in Action DEVELOPING ENTERPRISE APPLICATIONS WITH LIGHTWEIGHT FRAMEWORKS CHRIS RICHARDSON MANNING. Greenwich (74 w. long.)

Table of Contents. Introduction... xxi

C exam. IBM C IBM WebSphere Application Server Developer Tools V8.5 with Liberty Profile. Version: 1.

"Web Age Speaks!" Webinar Series

Enterprise Java Beans

1 Markus Eisele, Insurance - Strategic IT-Architecture

Enterprise JavaBeans TM

Transcription:

SIXTH EDITION Enterprise JavaBeans 3.1 Andrew Lee Rubinger and Bill Burke O'REILLY* Beijing Cambridge Farnham Kbln Sebastopol Tokyo

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

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 I Table of Contents

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 I vii

A Transactional Abstraction 141 Persisting Entities 142 Finding and Updating Entities 144 Removing Entities 147 refresh () 148 containso and clear() 148 flusho 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

Cascading PERSIST MERGE REMOVE REFRESH ALL When to Use Cascading 12. Entitv Inheritance Single Table per Class Hierarchy Advantages Disadvantages Table per Concrete Class Advantages Disadvantages Table per Subclass Advantages Disadvantages Mixing Strategies Nonentity Base Classes 13 Queries the Criteria API andjpaql Query API Parameters Date Parameters Paging Results Hints FlushMode JPAQL Abstract Schema Names Simple Queries Selecting Entity and Relationship Properties Constructor Expressions The IN Operator and INNER JOIN LEFT JOIN Fetch Joins Using DISTINCT The WHERE Clause and Literals The WHERE Clause and Operator Precedence The WHERE Clause and Arithmetic Operators The WHERE Clause and Logical Operators The WHERE Clause and Comparison Symbols The WHERE Clause and Equality Semantics 191 192 192 193 193 193 194 195 196 198 198 199 200 200 200 203 203 203 203 205 206 208 209 209 210 210 211 211 212 213 215 215 216 217 217 218 218 219 219 219 220 Table of Contents 1 ix

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 Table of Contents

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 I xi

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 Aroundlnvoke 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 WSDL1.1 371 The <defimtions> 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 38.1 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 I Table of Contents

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 @SOAPBmding 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 PartV. 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 I xiii

J. TimerService: CreditCard Processor Example 719 Index 727 xiv I Table of Contents