Enterprise Java and Rational Rose -- Part I - Working with EJBs
(Page 5 of 6 )
In order to create an EJB, the first thing you need to do is find its home object. You do this by using the "nickname" for the bean and querying the Java Naming and Directory Service (JNDI), such as Novell NDS, LDAP, etc.
Once you have a reference to the home object, you can invoke a create method on it. When a create is invoked on the home interface:
- The EJBHome creates an instance of the EJBObject and gives it the bean instance of the appropriate type to work with.
- Once the bean instance is associated with the EJBObject, the instance's ejbCreate() method is called.
- For entity beans, if a matching record already exists in the database, then the entity bean is populated from it; otherwise, a new record is inserted into the database.
- For session beans, the instance is simply initialized.
- Upon completion of the ejbCreate() method, EJBHome returns a remote reference for the EJBObject to the client. Remember that since we are dealing with remote objects, a remote reference is actually a stub.
- The client can now call business methods on the stub. The stub relays the methods to the EJBObject, which in turn delegates those methods to the bean instance (of the class we created), and the result is relayed back through the chain when the method returns
This sequence of events is shown graphically in Figure 6.

Next: Conclusion >>
More Development Cycles Articles
More By The Rational Edge