Java Reference
In-Depth Information
We're using JDBC for simplicity only because we haven't introduced the EJB 3 Persistence
API (JPA) in any detail yet. We don't want to assume that you already understand ORM.
Using JDBC also happens to demonstrate dependency injection of resources and the state-
less bean lifecycle callbacks. In general, you should avoid using JDBC in favor of JPA once
you're comfortable with it.
3.1.2. Component state and session bean types
As we alluded to earlier, component state is the fundamental distinguishing characteristic
of the three different types of session beans. The closest parallel to how stateless session
beans manage state is the original connectionless, sessionless HTTP web server request/re-
sponse cycle. The web browser requests a page and the server serves up the page and ends
the connection. The particular contents of the page might change from one request to the
other, but the browser doesn't expect the web server to maintain any client-, request-, or
session-specific information on the server side. This doesn't mean, however, that the web
server doesn't utilize state for its own internal functioning. For example, the web server
might keep an open connection to a remote file server, maintain an in-memory file cache,
and so on.
Stateless session bean clients similarly can't be expected to maintain state on behalf of a
client. A client can't even expect to be interacting with the same session bean instance
across invocations, and all stateless session bean invocations are atomic. With or without
pooling, clients are almost guaranteed to be talking to a different session bean instance
across each invocation. Even though a stateless session bean doesn't hold state specific to
a single client, it can and usually does internally make use of reusable resources like data-
base connections. Stateless session beans are ideal for business services that have atomic,
fire-and-forget API methods. The vast majority of Enterprise application services fall un-
der this category, so a majority of your session beans are likely to be stateless. In terms of
ActionBazaar, the BidService class is a prime candidate for a stateless session bean. As
figure 3.1 shows, it contains APIs to add, get, and remove bids (all operations that can be
completed in a single method call).
Search WWH ::




Custom Search