Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Transactions are enabled by default for all EJB3 session bean methods in an EJB3 application, so you don’t need to do anything special to put the confirm() method under a transaction. The transaction manager is started when an event handler thread starts (e.g., when the confirm() method is invoked). The transaction manager commits all the updates to the database at the end of the thread. Since the transaction manager tracks the thread, it manages the event handler method and all the nested method calls from inside the event handler.
If any database operation in the confirm() method fails and throws a RuntimeException, the transaction manager rolls back all database operations. For instance, if the hotel inventory reduction operation fails due to a database connection error, the booking save operation, which already executed, would be canceled as well. The database is returned to the state before the conversation, and Seam displays an error message instead of the confirmation number (see Figure 11.1). We discuss how to display a custom error page for the RuntimeException in Section 17.4; if you do not set up the custom error page, the server just displays the error stack trace in JBoss’s standard error page.