First page Back Continue Last page Graphics
ejbCreate( )
The bean class will have ejbCreate( ) methods:
- One to match each create( ) in home interface
- Called by container when it creates bean instance
What do these methods do?
- Generally used to initialize state data
- No-arguments version may be empty
To abort session creation:
- Throw javax.ejb.CreateException from ejbCreate()
- Checked exception; must be declared if used!
- Client sees failure of Home#create( )
- See example in notes...
Notes:
The ejbCreate( ) methods are called by the EJB container when a client calls the matching create( ). They all have the syntax shown above.
The bean class must have one of these methods to match each create( ) in the home interface. (And since that interface will have at least one, the bean class will have at least one ejbCreate( ).)
These methods are called by the container when it creates a bean instance. For stateful beans, this happens when the client calls the matching create(). For stateless, when the container populates the pool. They can be used to initialize data. To halt creation, throw a CreateException. And since CreateException is a subclass of Exception, you name it in the throws clause of the method.
ejbCreate( ) Example
This example illustrates the use of ejbCreate( ). It imagines a stateful session bean that talks a legacy application. It does so via a socket connection to the other application's server.
Continued...