5 Replies Latest reply on Apr 17, 2007 9:20 AM by fhh

    EntityManager available outside container ?

    gbasilico

      Hello,
      We are planning to migrate an application from EJB 2.1 to EJB3. Our application currently uses CMP entity bean and the client side is a SWT application (no servlet, no jsp). So in order to replace my old CMP i wanted to use the new persistence layer.

      My problem is that i'm trying to access an EntityManager outside the EJB container (see my other post here : http://www.jboss.com/index.html?module=bb&op=viewtopic&t=106320).
      After reading some articles, i found that EntityManager may not be accessible from outside the container (after adding a "jboss.entity.manager.jndi.name" property in my persistence.xml, i'm trying to get it from a jndi lookup but it returns null).

      So my question is : what is true ? Is it possible to access the entitymanager this way ? Or is it mandatory to use a session bean (with dependency injection of the EntityManager) to access it from the client side ?

      Thanks in advance.
      Regards,

      Guillaume Basilico

        • 1. Re: EntityManager available outside container ?

          Can't you use the factory pattern to get an entityManager? This would of course imply that you allow your clients to acces the db directly.

          Regards

          Felix

          • 2. Re: EntityManager available outside container ?
            gbasilico

            Felix, thank you for your answer.

            Well, the problem is that currently we use CMP entity beans, the transactions are managed by the container and we do not want to modify the client side (managing the transactions by hand). So i'm afraid using the factory is not the solution...

            Regards,

            Guillaume

            • 3. Re: EntityManager available outside container ?

              I don't think you can acess an entityManager remotely. Since it manages the loaded entities it would either have to have access to the remote (the client's) JVM (not possible) or turn every entity into a kind of stateful session bean so that they inform the entityManager about changes (very difficult but _theoretically_ possible).

              But then again: Maybe I am wrong.

              Regards

              Felix

              • 4. Re: EntityManager available outside container ?
                gbasilico

                Thank you for your reply.

                That's what i was thinking, unfortunately... In fact, i managed to access to the entitymanager thanks to a session bean or a servlet, which both are on the server side, but not from my client... Too bad.

                A last question : do you think another container (Glassfish or another one) could have implemented that ? (i can dream, no ? ;-) )

                Regards,

                Guillaume

                • 5. Re: EntityManager available outside container ?

                  I can't imagine anybody has actually implemented this. But I don't know...

                  Regards

                  Felix