0 Replies Latest reply on Oct 6, 2008 6:18 PM by deanhiller2000

    seam booking ex. question

    deanhiller2000

      I see the following code in seam booking example...



         @PersistenceContext(type=EXTENDED)
         private EntityManager em;
         
         @In 
         private User user;
         
         @In(required=false) @Out
         private Hotel hotel;
         
         @Begin     (3)
         public void selectHotel(Hotel selectedHotel)
         {
            hotel = em.merge(selectedHotel);
         }
         
         @End       (4)
         public void confirm()
         {
            em.persist(booking);
            facesMessages.add("Thank you, #{user.name}, your confimation number " + 
                              " for #{hotel.name} is #{booki g.id}");
            log.info("New booking: #{booking.id} for #{user.username}");
            events.raiseTransactionSuccessEvent("bookingConfirmed");
         }
         
         @End
         public void cancel() {}
      



      I have a few qustions on this
      1. Why is hotel merged, BUT user is NOT merged?
          We seem to always run into problems with merging user so we started having a session user and a conversation user ourselves to solve this like so....



          conversationScopedUser = mgr.merge(sessionScopedUser);



      If we don't do that and assign the sessionScopedUser back to the session, it screws up other conversations since each Conversation has it's own EntityManager and user can only be associated with one.


      2. If I click cancel, I would think any changes I made to the hotel would be saved to the database.  After all, how would it know I did not want to save hotel since I did a mgr.merge(hotel)...confirm will obviously save changes to hotel, but I think cancel does too(isn't this bad?)


      thanks for helping me get to that next level of understanding in the seam/EJB3/hibernate combo,
      Dean