[JBoss Seam] - Hotel Booking sample and Conversation - Why merge?
by 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())?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4086920#4086920
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4086920
18 years, 9 months
[JBoss Seam] - Re: question about conversation scope
by pete.muir@jboss.org
IIRC it was because without manual flush mode you had to be much more careful about not inadvertently calling an action methods as they all caused flushes. Anyway, this was a while ago when I used to write Seam apps and it made sense at the time. Of course, end the conversation if possible e.g. on a done button, but if the user is halfway through doing something then navigates elsewhere then I would not propagate rather than end the conversation.
I never used detached entities as that defeats the point of conversations/seam IMO.
BTW I'm hoping to really read your other threads about conversations when I have time and I hope we can take some of the lessons back into Seam to make it even better (at least improve the docs!).
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4086913#4086913
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4086913
18 years, 9 months