2 Replies Latest reply on Sep 21, 2007 12:42 PM by Ivan B

    Booking Example - Do I miss the point about transactions?

    Ivan B Novice


      If we have a look at the BookingListAction class (listed below), its transaction attribute suggests, that each method in that class will trigger a new transaction. My question is about the cancel() method, which as you can see removes the booking, and updates the list of bookings. What confuses me is that getBookings() is called from cancel(), before cancel() is finished, which means that cancel's transaction is not commited and no changes is made persistent. According to my understanding getBookings() should get the same unupdated list of objects, which makes no sense and in fact is not true. Can anyone kindly suggest what I miss here? Thanks

      public class BookingListAction implements BookingList, Serializable
       private static final long serialVersionUID = 1L;
       private EntityManager em;
       private User user;
       private List<Booking> bookings;
       private Booking booking;
       private Log log;
       public void getBookings()
       bookings = em.createQuery("select b from Booking b where b.user.username = :username order by b.checkinDate")
       .setParameter("username", user.getUsername())
       public void cancel()
       log.info("Cancel booking: #{bookingList.booking.id} for #{user.username}");
       Booking cancelled = em.find(Booking.class, booking.getId());
       if (cancelled!=null) em.remove( cancelled );
       FacesMessages.instance().add("Booking cancelled for confirmation number #{bookingList.booking.id}");
       public Booking getBooking()
       return booking;
       @Destroy @Remove
       public void destroy() {}