Wednesday, November 14, 2007

Difference between Session and Entity bean

Session beans and entity beans compared
Table 1 is a summary of the differences between entity and session beans.

Table 1. Comparison of session and entity beans
Session bean
Entity bean
Represents a single conversation with a client.
Typically, encapsulates an action or actions to be taken on business data.
Typically, encapsulates persistent business data—for example, a row in a database.
Is relatively short-lived.
Is relatively long-lived.
Is created and used by a single client.
May be shared by multiple clients.
Has no primary key.
Has a primary key, which enables an instance to be found and shared by more than one client.
Typically, persists only for the life of the conversation with the client. (However, may choose to save information.)
Persists beyond the life of a client instance. Persistence can be container-managed or bean-managed.
Is not recoverable—if the EJB server fails, it may be destroyed.
Is recoverable—it survives failures of the EJB server.
May be stateful (that is, have a client-specific state) or stateless (have no non-transient state).
Is typically stateful.
May or may not be transactional. If transactional, can manage its own OTS transactions, or use container-managed transactions.
A stateful session bean that manages its own transactions can begin an OTS transaction in one method and commit or roll it back in a subsequent method.
A stateless session bean that manages its own transactions and begins an OTS transaction must commit (or roll back) the transaction in the same method in which it was started.
The state of a transactional, stateful session bean is not automatically rolled back on transaction rollback. In some cases, the bean can use session synchronization to react to syncpoint.
May or may not be transactional. Must use the container-managed transaction model.
If transactional, its state is automatically rolled back on transaction rollback.
Is not re-entrant.
May be re-entrant.

Courtesy:http://publib.boulder.ibm.com/infocenter/cicsts/v3r1/index.jsp?topic=/com.ibm.cics.ts31.doc/dfhpj/topics/dfhpji2.htm

No comments: