Client View of Bean  «Prev  Next»

Lesson 5 Creating a session EJB
Objective Write Java Code in Client to create Session EJBs

Write Java Code in Client to create Session EJBs

The client's remote references

Write the Java code in the client to create session EJBs.
The client invokes the methods of the home interface to create its associated bean instance. There is a single home object for each session bean type and an EJBObject/ bean instance pair for each client.

The client's remote references
The client's remote references

On the creation of a new bean instance, the creation process will return a remote reference to the bean instance's EJBObject.

Home interface methods

ejb-exception
  1. interface HelloHome extends EJBHome - Home objects implement interfaces that always extend javax.ejb.EJBHome
  2. Hello create() - Creates the bean instance with a default state and returns a remote reference to the bean's EJBObject instance.
  3. Hello create(String arg1) - Creates a bean instance using the specified parameters to set the initial state rather than the default state.
  4. CreateException, RemoteException - The create methods must throw both these exceptions.
  5. All the EJB methods are in the "javax" package
EJB home Create Methods
Note that there must be, at least, a no-arg[1] create() method in the Home object.
The code in the client that creates the bean using the create(String) method will be as simple as:

Hello bean = home.create("Mickey");

During the evolution of the code, I will only show the important features. I will ignore exception handling, when not essential for understanding, as it adds clutter to the code samples. However, in all the complete examples, workshop solutions, etc., I will show full-strength code.

create() methods return remote references to the bean's EJBObject instance. If no exceptions are thrown, the bean instance will be created and is then ready to accept method calls.

Creating Session Bean - Quiz

Click the Quiz link below to test your understanding of session bean architecture and how to create session beans.
Creating Session Bean - Quiz
In the next lesson, you will be introduced to the code in the client to call the bean's methods.

[1]no-arg: A method that takes no arguments. For example create() in the home interface.