Transaction essentials try { utx.rollback(); } catch (RuntimeException
Transaction essentials try { utx.rollback(); } catch (RuntimeException rbEx) { log.error(”Couldn’t roll back transaction”, rbEx); } throw ex; } The session1 and session2 persistence context is now flushed automatically during commit of the UserTransaction, and both are closed after the transaction completes. Our advice is to use JTA directly whenever possible. You should always try to move the responsibility for portability outside of the application and, if you can, require deployment in an environment that provides JTA. Programmatic transaction demarcation requires application code written against a transaction demarcation interface. A much nicer approach that avoids any nonportable code spread throughout your application is declarative transaction demarcation. Container-managed transactions Declarative transaction demarcation implies that a container takes care of this concern for you. You declare if and how you want your code to participate in a transaction. The responsibility to provide a container that supports declarative transaction demarcation is again where it belongs, with the application deployer. CMT is a standard feature of Java EE and, in particular, EJB. The code we ll show you next is based on EJB 3.0 session beans ( Java EE only); you define transaction boundaries with annotations. Note that the actual data-access code doesn t change if you have to use the older EJB 2.1 session beans; however, you have to write an EJB deployment descriptor in XML to create your transaction assembly this is optional in EJB 3.0. (A stand-alone JTA implementation doesn t provide container-managed and declarative transactions. However, JBoss Application Server is available as a modular server with a minimal footprint, and it can provide only JTA and an EJB 3.0 container, if needed.) Suppose that an EJB 3.0 session bean implements an action that ends an auction. The code you previously wrote with programmatic JTA transaction demarcation is moved into a stateless session bean: @Stateless public class ManageAuctionBean implements ManageAuction { @TransactionAttribute(TransactionAttributeType.REQUIRED)
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.