3 Replies Latest reply on Sep 23, 2007 3:21 AM by wise_guybg

    Hotel Booking sample and Conversation - Why merge?

    gersonk

      The HotelBookingAction (SFSB) has an method that begins the long-running conversation (@Begin) called selectHotel(Hotel selectedHotel) . See below:

      @Stateful
      @Name("hotelBooking")
      @Restrict("#{identity.loggedIn}")
      public class HotelBookingAction implements HotelBooking
      {
      
       @PersistenceContext(type=EXTENDED)
       private EntityManager em;
      
       ...
      
       @In(required=false) @Out
       private Hotel hotel;
      
       @In(required=false)
       @Out(required=false)
       private Booking booking;
      
       ...
      
       @Begin
       public void selectHotel(Hotel selectedHotel)
       {
       hotel = em.merge(selectedHotel);
       }
      
      
       @End
       public void confirm()
       {
       em.persist(booking);
       facesMessages.add("Thank you, #{user.name}, your confimation number for #{hotel.name} is #{booking.id}");
       log.info("New booking: #{booking.id} for #{user.username}");
       events.raiseTransactionSuccessEvent("bookingConfirmed");
       }
      
       ...
      }
      


      The question is: why does use em.merge on 'selectedHotel'? What about em.find(Hotel.class, selectedHotel.getId())?