Implementing a Basic EJB

Now it’s time to discuss actually implementing an Enterprise JavaBeans component. If you are creating either an entity or a session bean, there are three Java interfaces/classes you need to provide:

Home interfaces

This is accessed directly by clients and used to create and/or find EJB objects of a specific type. An EJB can have both local and remote home interfaces, though in most cases only one or the other is needed, based on the context in which the EJB is being deployed.

Client interfaces

The interface (local or remote) for the bean is also accessed directly by clients. When a client creates or finds an EJB object through a home interface, it is given a reference to a stub that implements the interface for the bean. The interface defines the methods the EJB object exports to clients. As with home interfaces, an EJB can have both local and remote bean interfaces.

Bean implementation

The EJB object implementation itself must implement all the methods defined in its remote and local interfaces, provide methods that correspond to the methods on its home interface for creating and/or finding the bean, and also implement the methods used by the EJB container to manage the bean.

Message-driven beans require the bean implementation class only. They don’t have home interfaces or client interfaces since the client interface is implemented using JMS message-passing -- we’ll see more details on creating and using message-driven beans later in the chapter.

To demonstrate ...

Get Java Enterprise in a Nutshell, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.