1 Reply Latest reply on Sep 28, 2006 1:37 AM by Vishal Sharma

    EJB 3 merge vs persist

    heba hob Newbie

      Hi,

      I have a remote client using jndi (InitialContext) to grab remote interfaces of EJBs (I am using EJB3.0, so I am not talking about the home/remote difference, but I am grabbing the interface I have annotated as @Remote). If this client picks up an EntityManager with a standard persistence context, how should I put changes back to the server after changing the entity?

      Currently I use:

      mgr.merge( changedObject );
      mgr.persist( changedObject );
      


      I understand that persist works only if the entity is still in managed state according to the container. The two areas of confusion for me are:

      1. Does merge do the persist too? Or does it simply bring the entity back into persistent state, and then I need to persist() as above?

      2. Are all entity beans that are used from session bean stubs on remote clients pulled out of context? i.e. Do I have to always call merge if I use an entity bean [from a session bean] from a remote client?

      Thanks in advance

        • 1. Re: EJB 3 merge vs persist
          Vishal Sharma Expert

          What merge () does is - is to put back the detached entity back into persistence storage.
          So if in yr case- if yr entity was detached it will put it back to persistence which means you don't have to call persist again.

          For answer to part 2. - merge() method with throw an illegal Arguement Exception if its paramter is not an entity type.

          I hope this helps....