4 Replies Latest reply on Sep 25, 2006 6:39 PM by gavin.king

    Automatic Entity merge

    mcloud

      While looking at the examples considering if I'm going to switch from spring opensessioninview to seam I noticed something:

      @Begin
      public String selectHotel()
      {
      hotel = em.merge( hotelSearch.getSelectedHotel() );
      return "hotel";
      }

      That is called when a second view is about to open receiving an entity from another view (and session). Is there a way to seam do the merge by itself without me doing it by hand?

        • 1. Re: Automatic Entity merge
          pmuir

          It depends whether the entity is detached or managed by the container. As long as the entity is managed then unless you have transactions disabled or automatic flushing turned off then updates will be persisted by the container.

          • 2. Re: Automatic Entity merge
            gavin.king

            Within a conversation, this kind of code is unnecessary, because you can used a conversation-scoped extended persistence context. But if you want to pass an object from one conversation to another, you have to do something like this.

            One alternative approach is instead of passing the entity object around, just pass the id in a request parameter and use something like the ManagedEntity component (in Seam CVS) to auto-load the entity instance and expose it via a context variable. I love this approach and the new Seam crud framework will use this heavily.

            • 3. Re: Automatic Entity merge

               

              One alternative approach is instead of passing the entity object around, just pass the id in a request parameter and use something like the ManagedEntity component (in Seam CVS) to auto-load the entity instance and expose it via a context variable.


              Since request parameters can be easily manipulated by a malicious user, this seems like a pretty dangerous general approach to me. When you're searching a blog or providing REST services, this works great. For a general CRUD framework this worries me.

              For example, I wouldn't want my bank's online "add joint account member" conversation to take in currentUserId and newJointUserId as a request params.

              Of course, I haven't seen this thing in action, maybe there are safeguards in place to detect manipulation of these params. Please assuage my fears. :)

              • 4. Re: Automatic Entity merge
                gavin.king

                I don't mean it for this kind of case.