Best practices for developing enterprise beans
Use the following guidelines when designing and developing enterprise beans.
- Use a stateless session bean to act as the entry point for business logic. For more information about using session facades, see "Resources for learning."
- Entity beans should use container-managed persistence.
- In an EJB V2.x environment, use local interfaces to improve communication between enterprise beans in the same Java virtual machine.
Local calls avoid the overhead of RMI/IIOP and use pass-by-reference semantics instead of pass-by-value. For each call, the caller and callee beans share the state of arguments. EJB 2.x beans can have both a local and remote interface but more typically have one or the other.
- For communicating with remote clients, provide remote and remote home interfaces. For communicating with local clients like servlets, entity beans, and message-driven beans, provide local and local home interfaces.
Batched commands for container managed persistence
From JDBC 2.0 on, PreparedStatement objects can maintain a list of commands that can be submitted together as a batch. Instead of multiple database round trips, there is only one database round trip for all the batched persistence requests.
You can enable the use of this feature for EJB container managed persistence. When you do, the run time defers ejbStore/ejbCreate/ejbRemove or the equivalent database persistence requests (insert/update/delete) until they are needed. This can be at the end of the transaction, or when a flush is needed for finders related to this EJB type. When the persistence operation finally happens, run time accumulates the database requests and uses JDBC PreparedStatement batch operation to make a single JDBC call for multiple rows of the same operation.
The WAS enables you to make the same settings using the Application Server Toolkit (AST).
Deferred Create for container managed persistence
The specification for EJB 2.x states that for Container Managed Persistence (CMP) during the ejbCreate, the container can create the representation of the entity in the database immediately, or defer it to a later time.
The WAS versions 5.0.2 and later enable you to take advantage of this specification. You can turn this option on from the EJB CMP side. When you choose this option, the runtime defers ejbCreate (or the equivalent database persistence request) until it is needed. This can be at the end of the transaction, or when a flush is needed for finders related to this EJB type. By doing this you can reduce two round trips for the newly created entity (insert and update) to one (insert).
The WAS enables you to make the same settings using the Application Server Toolkit (AST).
Sub-topics
Partial column updates for container managed persistence
Related tasks
Task overview: Using enterprise beans in applications
Setting the run time for batched commands with JVM arguments
Setting the run time for batched commands with the assembly tools
Setting the run time for deferred create with JVM arguments
Setting the run time for deferred commands with the assembly tools
Related Reference
Enterprise beans: Resources for learning
Reference topic