First page Back Continue Last page Graphics
...Setting Context
What if bean can not get a needed resource?
- Throw EJBException to signal container
- Bean instance is not created
Q: When does client find out about failure?
A: Depends on type of bean:
- Stateful session bean: on Home#create( )
- Stateless session bean: on first business method call
- Entity bean: on Home#create( ) or Home#find*( )
Notes:
If the code in your set*Context( ) method fails in some critical way (such as failing to connect to a needed database), signal the failure to the container by throwing EJBException. This will abort creation of the bean instance.
When the client discovers the failure depends on the kind of bean. The container creates stateful session bean instances when the client calls the create( ) method of the home object, so the failure will be detected immediately. But for stateful session beans and entity beans, the container creates instances in advance for a pool. Only when the client calls a business method (in the first case) or create( ) or find*( ) (in the second case) will it learn that there is no bean instance to talk to.