Book Image

EJB 3 Developer Guide

By : Michael Sikora
Book Image

EJB 3 Developer Guide

By: Michael Sikora

Overview of this book

Table of Contents (18 chapters)
EJB 3 Developer Guide
Credits
About the Author
About the Reviewers
Preface
Annotations and Their Corresponding Packages

Controlling Container Managed Transactions


When using container managed transactions, the application usually just needs to demarcate any transactions. In general we do not need to explicitly commit or rollback a transaction: the container takes care of this. However sometimes we need to explicitly commit and rollback transactions even when using container managed transactions. We may want to use a cache with stateful session beans and commit the data when the cache is full rather than at the end of each transaction. To do this we need to implement the SessionSynchronization interface. This is described in the next subsection. In the course of processing a business method we may need to abort a transaction. This is done using the SessionContext.setRollbackOnly() method. This ensures the container will not commit the current transaction. We describe this in the "Doomed Transactions" subsection.

SessionSynchronization Interface

There are occasions when we want the application to have some control...