Java Reference
In-Depth Information
saw earlier in section 10.1, EJB 3 session beans are POJO s instead of classes that
implement EJB interfaces. They use dependency injection to obtain their depen-
dencies instead of JNDI . You configure them using simple annotations rather than
elaborate deployment descriptors. Moreover, they use transactions, security, and
remoting provided by the EJB container, which is extremely convenient.
We use the same techniques that we used in chapter 7 to design a POJO façade
to develop an EJB 3 session bean. First, we analyze the UI design to determine the
requests that the session bean must handle and the data that it exchanges with the
presentation tier. Next, we implement the session bean's methods by calling the
domain model classes. Finally, we implement a result factory that detaches the
objects required by the presentation tier. The only thing that is different is that
the EJB container rather than the Spring framework manages transactions.
We begin this section by describing how to turn the POJO façade such as the
one we developed in chapter 7 into an EJB 3 stateless session bean. After that we'll
discuss how a façade goes about detaching objects.
10.3.1
Turning a POJO façade into a session bean
Turning a POJO façade such as the PlaceOrderFacade we developed chapter 7 into
an EJB 3 session bean is pretty simple. No code changes are required other than
the addition of a public default constructor for use by the EJB container. Apart
from that one small change you just have to annotate the façade's interface and
implementation class. The interface is annotated with an @Local annotation if you
want a local interface or @Remote annotation if you want a remote interface:
@Local
public interface PlaceOrderFacade {
}
The implementation class is annotated with the @Stateless annotation and has a
default constructor:
@Stateless
public class PlaceOrderFacadeImpl
implements PlaceOrderFacade {
public PlaceOrderFacadeImpl() {
}
}
You can then deploy the bean in the EJB container and all calls to the façade will be
transactional. You can also use the EJB container's security mechanism, which
 
 
Search WWH ::




Custom Search