The container will not passivate entity beans or stateful session beans if they are in a transaction. It could passivate an entity bean in between transactions because this is the same as saying, "not in a transaction." It could passivate an entity bean between methods. In this case, when another client goes to use the same entity, the container will just bring another bean out of the pool to represent the entity. Different containers will have different passivation logic. It is not for you, the bean developer to worry about. One reason a container might passivate an entity bean is that it is running low on resources and no one has called a method on the bean in a while. [ March 01, 2004: Message edited by: Anthony Watson ]
The container will not passivate entity beans ... if they are in a transaction.
I used to think this was true, until I read a surprising passage in the spec [section 10.5.1, pg 169]:
The container can chose to passivate an entity bean within a transaction.
This may seem odd, but when you think about it, this can work for an entity bean. The container can do an ejbStore without doing a commit; the data is just hanging around on the server waiting for the commit at the end of the transaction, so the entity bean instance really isn't needed any longer.
As Reid said, SFSB cannot be passivated in a transaction. Entity beans can be passivated in a transaction by the container. The concept of passivation is different for SFSB and Entity bean, even though they both share the same name. Passivation of SFSB deals with the serialization of the bean's data, while passivation of entity beans deals with the bean being sent back to the pool.
If an entity bean is in the middle of a transaction why would the container want to passivate? How would that effect the transaction? I mean we are talking CMT here so it must be in the middle of a method and therefore doing something currently (or uber-badly programmed). It sort of worries me that mid way through changing a field on an entity the container just throws it back to the pool. What happens to the transaction? Does the pooled entity bean retain its lock on the database row?
SCJP (1.4), SCJD (1.4), SCWCD (1.3), SCBCD (1.3)
Sunglasses. AKA Coolness prosthetic. This tiny ad doesn't need shades:
a bit of art, as a gift, that will fit in a stocking