All CDI managed beans that belong to a scope that is ultimately bound to the HttpSession need to be serializable. Which means all attributes need to be serializable. EntityManager is not though this seems to be considered a bug (here and here (I don’t know why it’s closed.)).
This means if you want to adhere to the spec you cannot use JPA from CDI scopes like Session or Conversation.
Seems Java EE is close to unusable or what?
you’re right :
EntityManageris not serializable, but do you think CDI EG didn’t notice that 🙂 ?So when a CDI bean is Serialized (i.e. passivation of a SFSB) the EntityManager is considered as transient and is not. When then bean is unserialized the EntityManager is automatically re-injected in the Bean and so it works as it used to be.
The problem is when you use Extended Persistence Context in your Bean. Java EE spec doesn’t support serialization of such bean. But framework like Seam 2 for Java EE 5 or CDI extension like Seam3 Persistence in Java EE 6 gives you possibilities to manage those special use cases.