1 Reply Latest reply on Oct 15, 2005 8:15 AM by pomelo verde

    Should I do hierarchical EJB3s?

    platinumdragon Newbie

      I would love to get opinions on this. The example is a bit contrived, but hopefully it will get across what I'm after.

      Let's say we have a doctor EJB3:

      @Stateless
      public class DoctorBean implements Doctor
      {
       public Patient getPatient(String patientNumber);
      }
      


      Now, in addition to some basic information, Patient has a lot of complex data coming from, say, a database. I'm thinking that Patient should also be an EJB. That way I'm not getting the hi-res image of every X-ray taken of them needlessly serialized, when all I wanted is the last date of X-ray.

      The problem I see with this design is that it works great as long as the client is local. If I want to access this remotely, then I have to create an entirely different DoctorBean (DoctorRemoteBean) so that the Patient is also a RemotePatient.

      @Stateless
      public class DoctorRemoteBean implements RemoteDoctor
      {
       public RemotePatient getPatient(String patientNumber);
      }
      


      Does this make sense?

      Thanks,
      Mike

        • 1. Re: Should I do hierarchical EJB3s?
          pomelo verde Newbie

          Well, I think that first you should define a more robust Application Architecture. Using well proved design patterns is mandatory in order to create quality software.

          You should design a well defined Data Model. It will modeled with Entity EJB3 beans, that as POJOs, can be used as Data Transfer Objects too. The Entity beans can have relationships. For example, a Doctor could have a OneToMany relationship with Patient.

          In addition, you should be design a Business Logic layer, implemented with EJB3 Session Beans. The same Session Bean can implement a Remote interface and a Local interface.

          You can user the POJOs (annotated as Entity Beans) as parameters and returns values in the business methods implemented by the session beans.

          And remember... dont mix business logic within data model objects.

          I recommend you the "J2EE Architetc's Handbook" that you can download for free from www.theserverside.com.

          Enjoy EJB3!