Entity bean passivation by container

According to EJB Spec 2.0 , the container can passivate the entity bean in middle of transaction. The following is paragraph from ejb spec.

"The container can choose to passivate an entity bean instance within a transaction. To passivate an instance, the container first invokes the ejbStore method to allow the instance to synchronize the database state with the instance's state, and then the container invokes the ejbPassivate method to return the instance to the pooled state."

So if container passivate the bean in middle of transaction then it would invoke the ejbStore method and would update the database. So we are updating the database with-out knowing the transaction result ( commit or rollback ) In case of rollback, it would put the database in inconsistent state.

Could any one please explain it ?

Severin Stoeckli

Ranch Hand

Posts: 62

posted 12 years ago

Hi Sabari,

The point is the following:

(1) Storing something in the database means:

UPDATE data_info SET TITLE='Volcanos' WHERE ID = 100005; (=ejbStore)

(2) finishing a transaction means:

COMMIT

After (1) is running nobody else can see a change on the database until (2) runs (depending on your isolation level). The container may passivate your bean between (1) and (2).

Hope this helps

Severin

Sabari Unniramath

Greenhorn

Posts: 6

posted 12 years ago

thanx for ur response.

what i get from ur reply is this.. once the container acquires the lock for a particular row in the database for a transaction, the lock will be released only after the transaction completes, no matter whatever happens with passivation..am i right ???

Severin Stoeckli

Ranch Hand

Posts: 62

posted 12 years ago

yes, that's correct. Notice that "passivation" in Entity Beans is not the same as passivation in Stateful Session Beans. For Entity Beans it's only a "change of their role", not a "swap out to disk", although their state may be written to the disk too in ejbStore().