According to the spec, all stateless session beans, resources (including EntityManagerFactory and DataSource), and the UserTransaction are passivation capable dependencies, so you do not need to declare the injected fields transient.
This is a bug. I believe it is a bug in Weld that has already been fixed.
Thanks! Reading through 6.6.2, I now see that I am indeed assured that all SLSB and resources are going to be restored.
But I am still confused about transient. Since 6.6.1 says that my managed bean must be serializable, I must declare it so, and I can't very well lie about those dependencies. They aren't serializable, so it seems only proper to declare them as transient. I don't mind doing that--I just don't understand why you say it's not necessary. Does the app server not actually serialize the object when it passivates it?
They aren't serializable, so it seems only proper to declare them as transient.
The actual underlying resource may not be serializable by the proxified reference to it is. You should not declare the field transient.
Does the app server not actually serialize the object when it passivates it?
Exactly. It uses a proxy.
What about Conversation objects? Are they re-injected upon activation? Some static code analysis indicates that it is a non-serializable field. Or is my code analyser just annoying?
The way I read the spec is that if CDI injects it, it owns the relationship and it will reinject it.
As for the static code analyzer, that's a good point. I see no harm in declaring the fields as
transientto keep your static code analyzer happy.
There is no reinjection, after deseralization. What happens is CDI injects a serializable client proxy which is seralized along with the passivated object at least for normal scoped dependencies.
I have written a detailed blog post on their subject: https://www.knitelius.com/2016/05/18/cdi-passivation-uncovered/