Servlet-EJB Design. Please guide me

Discussions

EJB design: Servlet-EJB Design. Please guide me

  1. Servlet-EJB Design. Please guide me (3 messages)

    Hello....
    I'm currently designing a web application. The admin module is assigned to me so there's this scenario where the administrator can retrieve and update a user profile. I'm planning to design it in a way where the retrieving of the user profile is through a data access object, which directly access the database and returns a value object that represents the user profile. The rationale for such design is because retrieving user profile entity bean is not efficient since it will only be used for displaying purposes only. On the other hand, for updating the user profile, the servlet will retrieve the entity bean and update it through the setter methods. My question is "Is this the right way of doing it cause I think it's kind of inconsistent" or "Should I also use the entity bean for displaying the user profile?"

    I got this idea where the web tier directly accesses the database in the Pet Store Example (The Catalog). But the difference is that the system doesn't update the catalog.

    Please guide me.

    thanks in advance...
    Jerson
  2. Jerson,
    One possible pattern would be the "Details Object" pattern. I believe it is here on theserverside. It will basically allow you to call getDetails() on your entity bean and then pass a simple java details object to the UI.
    Now you can still use DAO in your bean to store/load the data.

    Good luck,
    Chris
  3. Well, there is the theoretically correct way, and there are optimizations. The theoretically correct way is to use a bean for both directions. In fact, I suspect that not doing this will lead to very confusing code.

    By all means, use detail objects for communicating complex data. You should shoot to make the number of remote calls the absolute minimum (one per request?).

    So, I suggest the following: write your bean the right way. Benchmark the performance and see if you have any problems. If you do, are they caused by the poor entity bean sitting between your servlet and the DB, or by something else? Finally, apply optimizations to eliminate the real bottlenecks. But you will not know where the real bottlenecks are until you assemble the system. It is better to start with a good clean design. Go for the bean in both directions.

    Gene Florintsev
    gene at ejbility dot com
  4. Thanks for anwering guys.
    Once more, I need your opinion.
    We plan to design our system similar to the Pet Store example with some modifications. We will not use web model which mean that the application will not maintain a cached version of the shopping cart and account in the web tier. Instead of the EJBController and WebController returning the list of models to be updated, it returns a HashMap of detail objects. All detail objects will then be stored to request object using the key as the binding name for the attribute and the servlet will forward it to a JSP. This detail objects will then be used for displaying.

    Thanks in advance.
    Jerson