• Post Reply Bookmark Topic Watch Topic
  • New Topic

why SessionBean interface doesn't have ejbCreate defined?

 
David Yuan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
Sorry if this is a FAQ. But I am curious why SessionBean interface
doesn't have the ejbCreate defined?
If ejbCreate is optional, we can create a Session Bean that can never
be created. Can somebody explain it?
Below is the definition of the interface:
public interface javax.ejb.SessionBean
extends javax.ejb.EnterpriseBean
{
public void setSessionContext(SessionContext ctx);
public void ejbPassivate();
public void ejbActivate();
public void ejbRemove();
}
Thank you for any insights in advance.
-David
 
Viktor Sadovnikov
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
ejbCreate() method is indead optional for session beans. The home interface of the stateful session beans is not requried to include create() method. This interface can include "create", which takes different set of parameter, which will result in ejbCreate(parameters) in the bean class.
In short, ejbCreate() method is not checked by compiler. Container generate its name based on methdos found in the home interface.
Regards, Viktor
 
David Yuan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Viktor,
Thank you for your reply. I understand SessionBean doesn't define ejbCreate, and neither EJBHome nor EJBLocalHome defines "create" method. What I don't know is the purpose for this design.
To me, it doesn't appear to be a careless mistake of the EJB designers. Therefore I am just wondering about the reason behind.
Regards,
David
 
Ken Boyd
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Container will check if you have "create" define in your bean class. Container has to implement EJB spec. Your Stateless session has container call back methods, 4 from session bean & 1 from home interface (i.e. create method). While stateful can have overloaded create methods as well as just create().
Hope this help.
 
David Yuan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason that I can think of so far for ejbCreate being left out of the SessionBean is there is no way to define a universal ejbCreate in the interface. The home interface's create and the remote interface's ejbCreate can have different parameters, which can't be predicted by the EJB spec authors.
Therefore they simply left it out of the interface of SessionBean, and mark it as a "Must" in the specs. Am I right?
-David.
 
Vishwa Kumba
Ranch Hand
Posts: 1066
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the create() method signatures in the home interface and in the bean class should match with each other. create() method is mandatory for SLSB and it can have only 1 create() method. SFSB can have multiple overloaded create() methods and should have atleast 1 create methods.
I simply have no idea why they left it out from SessionBean interface.
On the contrary, ejbActivate() and ejbPassivate() methods are not applicable to SLSB but still they are included in the SessionBean interface.
 
Ming Hu
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stateless session beans have one and only create() with no args. If you wanted to add ejbCreate() to SessionBean interface, the one with no args would be your only choice. But then, you would force stateful session beans to implement the no-arg create().
 
David Yuan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ming Hu,
Yes, that's exactly what I am thinking of...
-David.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!