@EJB in @ViewScoped managed bean causes java.io.NotSerializableException

@ViewScoped beans are stored in HTTP session. Any objects which are stored in the HTTP session needs to implement Serializable. See also JSF managed bean causing java.io.NotSerializableException during Tomcat deployment and java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException.

The NotSerializableException is usually self-explaining since it mentions the full qualified name of the class which needs to be serialized as well, but can’t be since it doesn’t implement Serializable.

However, in this particular case the name seems to indicate an autogenerated class, most likely autogenerated by the EJB container and thus completely out of your control.

I’ve never seen this problem before and Google also doesn’t seem to give much about this problem. Based on the stacktrace you’re using Glassfish v3, so I’d suggest to post an issue about that. In the meanwhile your best bet is probably to set the JSF view state saving to the server side instead.


Update: a similar problem in MyFaces suggests a JSF impl specific issue of using wrong classloader during deserialization. Upgrading the JSF impl should solve the problem: @EJB in @ViewScoped @ManagedBean causes java.io.NotSerializableException.

Leave a Comment