Servlet knowledge of entitiy bean objects

Discussions

EJB design: Servlet knowledge of entitiy bean objects

  1. Servlet knowledge of entitiy bean objects (4 messages)

    If i have a session bean A which has a method getRecords() that accesses an entity bean B by (for instance) calling B's findAll() method, can i pass the Collection of B objects straight back to the calling class? So if i call A.getRecords() from a servlet, is it ok for the servlet to 'know' about the class B by way of an import statement?

    I'm not using the servlet to call any of B's methods directly, but I'm passing a Collection of B objects back to the servlet via A.getRecords().

    is this bad design practise? I could have A.getRecords() process the Collection it receives from B.findAll() and put the data in some other data structure but I obviously don't want to if it's not necessary.

    So i suppose this breaks down into 2 questions:

    1. Is the above situation bad from a design point of view?
    2. Are there any performance-related issues with the above situation?

    Any thoughts appreciated.

    maurice

    Threaded Messages (4)

  2. zzz[ Go to top ]

    zXZX
  3. Yes that's bad design. Your EntityBean should only have a set of simple methods to CReate/Update/Delete itself. This been should not be available outside the EJB container.

    Use a stateless session bean to access the entity bean. So basicly you put your businesslogic in your stateless session bean.
  4. Use a stateless session bean to access the entity bean. So basicly you put your businesslogic in your stateless session bean.

    Please reread the post. That is what he is doing already.

    Maurice, you need to consider the call from servlet to SB as a boundary. Within the SB, it can do what it wants, but you need to decouple it from what the servlet wants to do.

    The normal way to do this is via data transfer objects (DTOs). These are small data-only objects that are populated from (and often by) the entity beans, and then passed back up to the SBs client. This way, servlet, SB and EB all depend on the DTOs, but the servlet doesn't have to know anything about the EBs themselves. It just gets data. It could be anything in the SB that put it there, even plain JDBC.

    HTH
    Kit
  5. Thanks[ Go to top ]

    Thanks Kit, that's what i was looking for.
    Maurice
    Use a stateless session bean to access the entity bean. So basicly you put your businesslogic in your stateless session bean.
    Please reread the post. That is what he is doing already.Maurice, you need to consider the call from servlet to SB as a boundary. Within the SB, it can do what it wants, but you need to decouple it from what the servlet wants to do.The normal way to do this is via data transfer objects (DTOs). These are small data-only objects that are populated from (and often by) the entity beans, and then passed back up to the SBs client. This way, servlet, SB and EB all depend on the DTOs, but the servlet doesn't have to know anything about the EBs themselves. It just gets data. It could be anything in the SB that put it there, even plain JDBC.HTHKit