Chapter 7. Application and system design guidelines 163
򐂰 Use JavaBeans as helper objects to get work done.
Use JavaBeans as general-purpose utility elements, but avoid using helper
objects in create() and finder methods in entity beans. This makes reuse of
the bean challenging and deployment difficult.
򐂰 Wherever possible use stateless session beans.
Stateless session beans can be pooled by the EJB container for efficiency,
since they do not retain data between client invocations.
򐂰 Use session beans as facades to entity beans.
This prevents a new transaction from being created on every method call, and
eliminates the need to code business logic to back out a failed transaction.
򐂰 Use Container Managed Persistence (CMP) entity beans in most cases.
Use Bean Managed Persistence (BMP) for situations requiring complex SQL
or relational joins. When using BMP, always use WebSphere data source
objects and connection pooling.
򐂰 Cache read-only objects in a Singleton JavaBean.
Cache read-only objects or objects that do not change state on a per-JVM
basis by storing them in a Singleton JavaBean. Access these objects using a
stateless session bean.
򐂰 Use session beans for write-only objects.
For write-only objects that do not need to be read into memory, such as a log
entries, use session beans or consider using asynchronous messaging.
򐂰 Cache the EJB home interface.
Looking up the context, the remote home, and the remote interface is
expensive, so cache the home interface to improve performance. Beware of
stale handles.
򐂰 EJB local versus remote interface
Only provide a local interface for entity EJBs. This ensures that fine-grained
entity access is only available within the JVM. Provide remote coarse-grained
entity access using a session bean as a facade.
See also the best practice recommendations in publication EJB 2.0 Development
with WebSphere Studio Application Developer, SG24-6819, for further details.
7.3 Design guidelines for Web services
In this section we discuss the following Web services topics:

Get Patterns: Implementing Self-Service in an SOA Environment now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.