Make a web site - CHAPTER 11 Implementing conversations public void endAuction(Item item)

CHAPTER 11 Implementing conversations public void endAuction(Item item) { // 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 … } … } The current Session is bound to the transaction that is started for the endAuction() method, and it s flushed and closed when this method returns. All code that runs inside this method and calls sessionFactory.getCurrentSession() gets the same persistence context. If you compare this example with the first nonworking example, listing 11.1, you ll see that you had to add only some annotations to make it work. The @TransactionAttribute is even optional it defaults to REQUIRED. This is why EJB 3.0 offers a simplified programming model. Note that you haven t used a JPA interface so far; the data access classes still rely on the current Hibernate Session. You can refactor this easily later concerns are cleanly separated. You now know how the persistence context is scoped to transactions to serve a particular event and how you can create more complex data-access operations that require propagation and sharing of a persistence context between several objects. Hibernate internally uses the current thread or the current JTA system transaction to bind the current Sessionand persistence context. The scope of the Session and persistence context is the same as the scope of the Hibernate Transaction or JTA system transaction. We now focus on the second design concept that can significantly improve how you design and create database applications. We ll implement long-running conversations, a sequence of interactions with the application user that spans user think-time.
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Leave a Reply