O'Reilly logo

Java Enterprise in a Nutshell, Second Edition by David Flanagan, Jim Farley, William Crawford

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required