What's the difference between EJBHome, EJB Home, EJB Object, EJBObject and EJB(not to mention Home Interface and Remote Interface)?

Alex Chaffee

The EJB spec is all about really bad naming decisions.

First, an Enterprise JavaBean is not a JavaBean (but you already knew that).

The "Home Interface" is actually a Factory Object. It is responsible for locating or creating instances of the desired bean, and returning remote references.

When you write the source code for the EJB Home Interface, you must extend the interface EJBHome, and provide method signatures for all the desired create() and find() methods. An object that implements the Home Interface is automatically generated by the EJB Server tools.

The "EJB Object", or Remote Object, is actually a Wrapper. It sits somewhere inside the container, between the client and your code. It is responsible for performing all the setup and shutdown tasks (like opening transactions, or restoring data state) immediately before and after your enterprise bean is called.

The "EJB Object" is generated by the EJB Server tools -- you don't have to write any part of it. However, you do have to write another interface, called the "Remote Interface" or the "EJBObject Interface," that extends interface EJBObject, and provides method signatures for all the business methods. The server automatically generates a Java class that implements the Remote Interface; it is this object that is registered with RMI, and a reference to it is returned by the Home Interface (which we now know is actually a Factory Object).

The "EJB," or Enterprise Bean, ironically, is not the EJB Object (even though it is an EJB and it is an object). It doesn't even implement the EJBObject interface, nor does it implement the Remote Interface. Instead, it implements either the EntityBean interface or the SessionBean interface. It also must implement all the methods defined in the Remote Interface -- but it doesn't actually implement the interface (in the Java sense). This is unfortunate, since we cannot rely on the Java compiler to make sure we've implemented all the right methods. It must also implement one ejbCreate() method for each create() method in the Home Interface (as well as ejbFind()/find()).

See what I mean about poorly chosen names? :-)