Book Image

EJB 3.1 Cookbook

By : Richard M. Reese
Book Image

EJB 3.1 Cookbook

By: Richard M. Reese

Overview of this book

<p>Enterprise Java Beans enable rapid and simplified development of secure and portable applications based on Java technology.Creating and using EJBs can be challenging and rewarding. Among the challenges are learning the EJB technology itself, learning how to use the development environment you have chosen for EJB development, and the testing of the EJBs.<br /><br />This EJB 3.1 Cookbook addresses all these challenges and covers new 3.1 features, along with explanations of useful retained features from earlier versions. It brings the reader quickly up to speed on how to use EJB 3.1 techniques through the use of step-by-step examples without the need to use multiple incompatible resources. The coverage is concise and to the point, and is organized to allow you to quickly find and learn those features of interest to you.<br /><br />The book starts with coverage of EJB clients. The reader can choose the chapters and recipes which best address his or her specific needs. The newer EJB technologies presented include singleton beans which support application wide needs and interceptors to permit processing before and after a target method is invoked. Asynchronous invocation of methods and enhancements to the timer service are also covered. <br /><br />The EJB 3.1 CookBook is a very straightforward and rewarding source of techniques supporting Java EE applications.</p>
Table of Contents (19 chapters)
EJB 3.1 Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using the SessionSynchronization interface with session beans


When a transaction executes as part of a stateful session bean, the bean can receive synchronous notifications of the progress of the transaction using the SessionSynchronization interface. While there is not a specific field or variable which indicates the state of a transaction when using CMT, the invocation of one of its interface methods implies the transaction's state.

One possible use of this technique is to synchronize the instance variables of the bean to their corresponding values in a database. In this recipe, we will examine how the interface works. In the next recipe, Understanding how the TransactionAttributeType affects transactions, we will demonstrate how CMT work with different transaction attribute type settings.

Getting ready

The steps for using the SessionSynchronization interface include:

  1. Declaring that the class implements the interface

  2. Implementing the methods of the interface

In order for a stateful session...