I realized that statefull session bean with extended entity manager is not able passivate.
Take a look at this example:
public @Stateful class EBProxySB<T extends EB> implements EBProxy<T>, Serializable
{
private static final long serialVersionUID = 1169653273427828251L;
@PersistenceContext(type=PersistenceContextType.EXTENDED)
protected EntityManager manager;
protected boolean bound = false;
private T entity;
public T getEntity()
{
return entity;
}
public void setEntity(T ent)
{
entity = ent;
}
public boolean isBound()
{
return bound;
}
...
}
If this session bean is not removed whithin 5 minutes after creation, JBoss tries to passivate it but the passivation process fails with an exception "Not serializable".
I tried to find out where is the problem and realized that extented persistence manager has an aggregated member of class TransactionImpl which is NOT serializable. I took a look in the source and found out that persistence context is only serialized when the entity manager is not transient:
public void writeExternal(ObjectOutput out) throws IOException
{
out.writeBoolean(isTransient);
out.writeObject(initialContextProperties);
if (!isTransient)
{
out.writeObject(persistenceContext);
}
}
After annotating entity manager as @Transient, the session bean was able to passivate but then the activation process failed with an exception (with description "Entity manager factory is not bound").
The only workaround I can see is to increase the passivation timeout which is not very handy.
Has anybody a solution for this problem ?