Discussions

EJB programming & troubleshooting: qusetion about ejb inheritance

  1. qusetion about ejb inheritance (5 messages)

    hello
    in my ejb tier,i have several session bean,all of them share several common method,such as "readEmployee().....",etc.
    in not order to repeatly code them in every session bean,i want to wirte a base session bean which have remote,home and iomplementing class just same as the normal session bean,then other session beans can inherit from the base bean by all of the remote,home interface and the ejb implementation,so that the common method can be shared among multiple session bean.

    Threaded Messages (5)

  2. qusetion about ejb inheritance[ Go to top ]

    who can tell me is that a correct solution?

    thank you
  3. qusetion about ejb inheritance[ Go to top ]

    Hi!

    Your solution will work fine! And I havn't found any information saying this is illegal or bad practice. I have made the same for Entity Beans, and it worked fine!

    On the remote interface side, write a super interface (CommonRemote) having the method readEmployee(). Let all the beans' remote interfaces extend that interface.

    Then just write a CommonBean implementing SessionBean. You can also implement the "normal" implementations of the ejb-methods in that common bean. That will save you and the development team a lot of time!

    Finally, note that the beans cannot have a common home interface, since the create methods for different beans has to return the remote interface for that bean.

    /Tomas
  4. qusetion about ejb inheritance[ Go to top ]

    You may want to re-examine your design to see if inheritence works the best, rather than having an EJB do that common functionality that all your beans can then reference.

    You mentioned as an example readEmployee(), and if this is something that subclasses won't override, and that should always happen the same way, inheritance may not be the best idea. Rather create a session bean that does readEmployee and have all your beans reference and use that.

    Try to avoid using inheritance as a cheap way to given bean's access to the same method.

    That said, it IS a good idea to make a so-called Session Bean adapter, as the previous poster mentioned, that implements all the ejbRemove, ejbActivate, etc. mumbo-jumbo.
  5. Nothing complex, you can use all the object oriented concepts to the ejb Beans and remember its just an another Class which services to your RMI client . You might think a better way of saving the service time.
  6. thank you very much!