Cool web site - CHAPTER 11 Implementing conversations pattern.) You have to
CHAPTER 11 Implementing conversations pattern.) You have to enable this binding in your Hibernate configuration by setting the hibernate.current_session_context_class property to thread. If you deploy your application with JTA, you can enable a slightly different strategy that scopes and binds the persistence context directly to the system transaction. 11.1.3 Propagation with JTA In previous sections, we always recommended the JTA service to handle transactions, and we now repeat this recommendation. JTA offers, among many other things, a standardized transaction demarcation interface that avoids the pollution of code with Hibernate interfaces. Listing 11.3 shows the ManageAuction controller refactored with JTA. Listing 11.3 Transaction demarcation with JTA in the controller public class ManageAuction { UserTransaction utx = null; ItemDAO itemDAO = new ItemDAO(); PaymentDAO paymentDAO = new PaymentDAO(); public ManageAuction() throws NamingException { utx = (UserTransaction) new InitialContext() .lookup(”UserTransaction”); } public void endAuction(Item item) throws Exception { try { // Begin unit of work utx.begin(); // Reattach item itemDAO.makePersistent(item); // Set winning bid Bid winningBid = itemDAO.getMaxBid( item.getId() ); item.setWinningBid(winningBid); item.setBuyer( winningBid.getBidder() ); // Charge seller Payment payment = new Payment(item); paymentDAO.makePersistent(payment); // Notify seller and winner … // End unit of work utx.commit(); } catch (Exception ex) { try {
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.