Enterprise application "modalities":

An EJB container provides many services to the EJB:

If you don't need any of this stuff, then don't use EJB.

Enterprise JavaBeans:

An EJB cannot:

To perform these activities, you must put them on an external RMI or CORBA server.

Stateless SessionBean:

Stateful SessionBean:

EntityBean:

StateLESS Session Bean StateFUL Session Bean Entity Bean
More scalable, less powerful Consumes more resources on the server Overkill for read-only access to large data sets
Performs tasks independent of the client connected Performs tasks for a single client Controls shared access to transactional data
void ejbCreate() void ejbCreate(arguments), can be overloaded PrimaryKey ejbCreate(arguments), can be overloaded, void ejbPostCreate(arguments)
Remote create() Remote create(arguments) Remote create(arguments), Remote findByPrimaryKey(pk)
Never passivated and activated Can only be passivated when they are not participating in a transaction Can be passivated even during a transaction.
Get from pool, delegate method, put to pool No swapping or pooling of instances - SFSBs are dedicated to one client for their entire life. Cached (fast, instance maintains exclusive access), Stale (instance stays ready but data is stale), Pooled (scalable)
Can drive transactions, but not receive callbacks Transactionally aware (SessionSynchronization interface) Transactional object (ejbLoad and ejbStore)
SBs can use either CMTD or BMTD. Set transaction atttribute on business methods only. SessionSynchronization interface only with CMTD. EBs must use CMTD. Set transaction atttribute on most technical methods and all business methods.
Reentrant/loopback okay Not allowed Configurable
Container routes concurrent calls to different instances Concurrent calls from one or more clients are illegal. Clients should not “share” their Stateful Session Beans. Container manages concurrency through transactions

A transaction:

Transactions serve these functions in J2EE:

MVC (servlets talking to EJBs responding to clients through JSP)

Read-only access to large data sets

Quotes: