5 Replies Latest reply on Jul 16, 2006 9:49 AM by lucluc

    Client access to Entity beans

    doug.palmer

      I'm really stuck here; is it possible to connect to an Entity Bean deployed on JBoss 4.0.4 with EJB3 from a standalone client? Can anyone post a link to an example? I've found lots of examples with a session bean between the client and the entity but I can't find any examples where the client connects to the entity directly.

      Regards
      Doug

        • 1. Re: Client access to Entity beans
          starksm64

          There are several examples in the tutorial:
          http://docs.jboss.org/ejb3/app-server/tutorial/index.html

          • 2. Re: Client access to Entity beans
            doug.palmer

             

            "scott.stark@jboss.org" wrote:
            There are several examples in the tutorial:
            http://docs.jboss.org/ejb3/app-server/tutorial/index.html


            I'm sorry Scott but would you mind being more specific? I've already read through many of those tutorials but I can't find any in which Client.java connects to an Entity bean.

            Regards
            Doug

            • 3. Re: Client access to Entity beans
              lucluc

              From Entity Bean tutorial:

              Entity Beans have been given a complete overhaul in EJB 3.0. Entity beans are plain Java objects that can be allocated with new and attached/detached/reattached to persistence storage. Entity beans are not remotable and must be access through the new javax.persistence.EntityManager service. JBoss's EJB 3.0 implementation is built on top of Hibernate.

              So with ejb3, the facade pattern, is not an option anymore.

              bye
              F

              • 4. Re: Client access to Entity beans
                doug.palmer

                 

                "fguerzoni" wrote:
                From Entity Bean tutorial:

                Entity Beans have been given a complete overhaul in EJB 3.0. Entity beans are plain Java objects that can be allocated with new and attached/detached/reattached to persistence storage. Entity beans are not remotable and must be access through the new javax.persistence.EntityManager service. JBoss's EJB 3.0 implementation is built on top of Hibernate.

                So with ejb3, the facade pattern, is not an option anymore.

                bye
                F


                Ok, I've put a session bean in front of my entities now, following the MVC pattern. I guess my initial question should have read:

                How can I instantiate an Entity Manager on a stand alone client?

                I had already figured out that the client couldn't connect directly to an entity bean. However, all of my attempts to instantiate an entity manager on a client failed. Is there a mechanism for starting an entity manager in the client which persists data to a remote Jboss server?

                Regards
                Doug

                • 5. Re: Client access to Entity beans
                  lucluc

                  It's not MVC pattern, but FACADE pattern.

                  You don't need an EM on client, because EM can't do anything for you on client for client-server applications.
                  EM performs transactionally CRUD operations on server.
                  You have two options:
                  1) passing detached object to client, let client work on them, and eventually reattach them to EM on server -> less code
                  2) converting entities (model) to dto object and viceversa -> more flexibility

                  At the moment I've chosed the second option because I can't download to client all the Hibernate classes required to manage detached entity.
                  In the second case try out Dozer, it's a mapping library that does all the bidirectional mapping between model and dto quite automagically.


                  If your application is a standalone application, without server connection, so you have the database directly on client, you must bootstrap an embedded container and follow the general ejb3 tutorial. There's a lot of sample that explain how to do that.


                  ciao
                  F