EJB Cookbook
EJB Cookbook
BENJAMIN G. SULLINS
MARK B. WHIPPLE
M A N N I N G
Greenwich
(74° w. long.)
For online information and ordering of this and other Manning books, visit
www.manning.com. The publisher offers discounts on this book when ordered in
quantity. For more information, please contact:
Special Sales Department
Manning Publications Co.
209 Bruce Park Avenue
Fax: (203) 661-9018
Greenwich, CT 06830
email: manning@manning.com
©2003 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted,
in any form or by means electronic, mechanical, photocopying, or otherwise, without
prior written permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products
are claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial
caps or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books they publish printed on acid-free paper, and we exert our best efforts to that end.
.
Manning Publications Co.
Copyeditor: Liz Welch
209 Bruce Park Avenue
Typesetter: Dottie Marsico
Greenwich, CT 06830
Cover designer: Leslie Haimes
ISBN 1930110944
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 – VHG – 06 05 04 03
To Jenny, Elijah, and Samuel
—Ben
To my wonderful wife, Margie,
and my son, Alexander
—Mark
contents
preface
xv
acknowledgments
xvii
about this book xviii
author online
xxii
about the cover illustration xxiii
PART I APPETIZERS ....................................................... 1
1 Client code 3
1.1
Invoking a local EJB from another EJB 4
1.2
Invoking a remote EJB from another EJB 6
1.3 Accessing EJBs from a servlet 8
1.4
Invoking an EJB from a JavaServer Page 12
1.5
Invoking EJB business logic from a JMS system 15
1.6 Persisting a reference to an EJB instance 18
1.7 Retrieving and