This chapter describes how Enterprise JavaBeans (EJBs) work in the NAS application programming model.
What Enterprise JavaBeans Do
What Is an Enterprise JavaBean?
Session Beans and Entity Beans
The Role of EJBs in NAS Applications
Designing an Object-Oriented Application
Creation and management of beans is handled at runtime by a container. NAS itself provides the container for enterprise beans you write as part of your server application.
Customization of beans is handled at deployment time by editing the beans' environment properties.
Manipulation of metadata, such as transaction mode and security attributes, are separated from the enterprise Bean class, and handled instead by the container's tools at design and deployment time.
Mediation of client access is handled by the container and the server where the bean is deployed, freeing the bean designer from having to process it.
Restricting a bean to use standard container services defined by the EJB specification guarantees that the bean is portable and can be deployed in any EJB-compliant container.
Including a bean in, or adding a bean to an application made up of other, separate bean elementsa "composite" applicationdoes not require source code changes or recompiling of the bean.
Definition of a client's view of a bean is controlled entirely by the bean developer. The view is not affected by the container in which the bean runs or the server where the bean is deployed.
Life cycle: For EJB session beans, this includes implementation of the javax.ejb.SessionBean and javax.ejb.SessionSynchronization interfaces. For EJBs entity beans, it includes instead implementation of the javax.ejb.EntityBean interface.
Session context: A container implements the javax.ejb.SessionContext interface to pass services and information to a session bean instance when the bean instance is created.
Entity context: A container implements the javax.ejb.EntityContext interface to pass services and information to an entity bean when the bean instance is created.
Environment: A container implements java.util.Properties and makes it available to its EJBs.
Services information: A container makes its services available to all its EJBs.
File manifest entries that describe the contents of the file.
Java class files for the bean(s) in the file.
Deployment descriptors that include the declarative attributes associated with a bean. These attributes tell the container how to manage the bean.
Environment properties that the bean(s) require at runtime.
Executes in relation to a single client.
Optionally handles transaction management according to property settings.
Optionally updates shared data in an underlying database.
Is relatively short-lived.
Is not guaranteed to survive a server crash.
Represents data in the database.
Is always transactional.
Allows shared access for any number of users.
Can exist as longs as its data in a database.
Can transparently survive crashes of the EJB server.
Keep the central and application-specific parts of your application in as few, larger, entity EJBs as possible.
Restrict most of your long-term database connectivity to your entity EJBs.
Ask your administrator to co-locate EJBs with your presentation logic (servlets and JSPs) on the same server to reduce the number of remote procedure calls (RPCs) when you run your application.
Create stateless session beans instead of stateful session beans as much as possible. If you must create stateful session beans, have your administrator turn on sticky load balancing for better performance.
Create session EJBs that are small, generic, and narrowly task-focused. Ideally, these EJBs encapsulate behavior that can be used in many of your applications.