2. Using the Tutorial Examples 3. Getting Started with Web Applications 5. JavaServer Pages Technology 7. JavaServer Pages Standard Tag Library 10. JavaServer Faces Technology 11. Using JavaServer Faces Technology in JSP Pages 12. Developing with JavaServer Faces Technology 13. Creating Custom UI Components 14. Configuring JavaServer Faces Applications 15. Internationalizing and Localizing Web Applications 16. Building Web Services with JAX-WS 17. Binding between XML Schema and Java Classes 19. SOAP with Attachments API for Java 21. Getting Started with Enterprise Beans 23. A Message-Driven Bean Example 24. Introduction to the Java Persistence API 25. Persistence in the Web Tier 26. Persistence in the EJB Tier 27. The Java Persistence Query Language 28. Introduction to Security in the Java EE Platform 29. Securing Java EE Applications 31. The Java Message Service API 32. Java EE Examples Using the JMS API Container-Managed Transactions Summary of Transaction Attributes Setting Transaction Attributes Rolling Back a Container-Managed Transaction Synchronizing a Session Bean's Instance Variables Methods Not Allowed in Container-Managed Transactions Transactions in Web Components 36. The Coffee Break Application | Bean-Managed TransactionsInbean-managed transaction demarcation, the code in the session or message-driven bean explicitly marks theboundaries of the transaction. Although beans with container-managed transactions require less coding, they haveone limitation: When a method is executing, it can be associated with eithera single transaction or no transaction at all. If this limitation will makecoding your bean difficult, you should consider using bean-managed transactions. The following pseudocode illustrates the kind of fine-grained control you can obtain withapplication-managed transactions. By checking various conditions, the pseudocode decides whether to start orstop different transactions within the business method. begin transaction... update table-a... if (condition-x) commit transaction else if (condition-y) update table-b commit transaction else rollback transaction begin transaction update table-c commit transaction When coding a application-managed transaction for session or message-driven beans, you must decidewhether to use JDBC or JTA transactions. The sections that follow discuss bothtypes of transactions. JTA TransactionsJTA is the abbreviation for the Java Transaction API. This API allows youto demarcate transactions in a manner that is independent of the transaction managerimplementation. The Application Server implements the transaction manager with the Java Transaction Service (JTS).But your code doesn’t call the JTS methods directly. Instead, it invokes theJTA methods, which then call the lower-level JTS routines. A JTA transaction is controlled by the Java EE transaction manager. You may want touse a JTA transaction because it can span updates to multiple databases fromdifferent vendors. A particular DBMS’s transaction manager may not work with heterogeneous databases. However,the Java EE transaction manager does have one limitation: it does not supportnested transactions. In other words, it cannot start a transaction for an instanceuntil the preceding transaction has ended. To demarcate a JTA transaction, you invoke thebegin,commit, androllbackmethods of thejavax.transaction.UserTransaction interface. Returning without CommittingIn a stateless session bean with bean-managed transactions, a business method must commitor roll back a transaction before returning. However, a stateful session bean doesnot have this restriction. In a stateful session bean with a JTA transaction, the association between thebean instance and the transaction is retained across multiple client calls. Even ifeach business method called by the client opens and closes the database connection,the association is retained until the instance completes the transaction. In a stateful session bean with a JDBC transaction, the JDBC connection retainsthe association between the bean instance and the transaction across multiple calls. Ifthe connection is closed, the association is not retained. Methods Not Allowed in Bean-Managed TransactionsDo not invoke thegetRollbackOnly andsetRollbackOnly methods of theEJBContext interfacein bean-managed transactions. These methods should be used only in container-managed transactions. For bean-managedtransactions, invoke thegetStatus androllback methods of theUserTransaction interface. Copyright © 2010, Oracle and/or its affiliates. All rights reserved.Legal Notices |