Discussions

EJB programming & troubleshooting: Can Session bean be extended

  1. Can Session bean be extended (6 messages)

    Can a Stateless Session Bean be extend in another Stateless Session bean. If yes, how does the container works when an method is invoked on the sub class

    Threaded Messages (6)

  2. Absolutely![ Go to top ]

    Yes, you can easily extend a stateless session bean much in the same manner as you would extend an ordinary class. When you extend the remote interface of the parent bean, the child bean automatically can access the remote business methods of the parent, and therefore there is no need to specify the method signatures of the parent in the child unless you plan to override the methods. The child bean class would need to extend the parent bean class, and again, only specify the business methods that you plan to override. For the home interface, the child home should extend EJBHome, not the parent home, and it should be clear as to why this is since when your client call home.create() you are most likely returning an remote interface instance of the child, not the parent.

    In the deployment descriptor, you need only specify the classes and jndi names of the child bean provided that your application does not have a need to use the parent bean directly, and if it does, then you will need to specify the classes and jndi name for the parent as well.

    Hope it helps!

    Raffi
  3. What is the Benifit ?[ Go to top ]

    Hello ,
    Please can you explain me the need for extending the Session bean. I am not able to visiualize the need to do it.
    Also please tell me if possible what are the drawbacks of it..


    Alok Garg
  4. What is the Benifit ?[ Go to top ]

    If you dont extend the session bean of the parent bean, then your client calling the bean cannot make use of the business methods in the parent. It's simple OO basics and really has nothing to do with EJB.

    Raffi
  5. What is the Benifit ?[ Go to top ]

    Hello,
    So what I understood from the reply is that if I extend the parent bean then the user can also access the methods present in the parent bean.
    Now, just tell me one thing will the life cycle of the parent will depend on the childs life cycle.

    Is this a design pattern??

    Thanking you
    Alok Garg
  6. Absolutely![ Go to top ]

    That was a good explanation

    I would like to know one more thing, If a statefull session bean is extended then does the container maintain the state of parent and child Separately or how does it maintain.
  7. Depends on the container[ Go to top ]

    I think that depends on the container implementation. I mean that depends on the EJB Server how they implements. CSJakharia