- Start a new web application using NetBeans 7 on GlassFish 3.1
- In index.xhtml body add an
h:outputTexttag withvalue="#{myBean.message}" - Create a
SessionScopedManagedBeanMyBeanwith a String property calledmessage; create getter and setter; make it implementSerializable - Create a
StatelessSessionBeanand inject it intoMyBeanusing@EJBannotation - From this point on, whenever you change the Java code and save the project, you will get plenty of errors (NPE, IOError, EJB errors) during undeployment. The deployment is fine, and the application runs well. But I would like to avoid the exceptions during undeployment.
Is this normal? Or am I doing something wrong?
Here my code:
Index.xhtml (body part)
<h:body>
<h:outputText value="#{myBean.message}"></h:outputText>
</h:body>
MyBean.Java
@ManagedBean
@SessionScoped
public class MyBean implements Serializable {
@EJB NewSessionBean nsb;
public String getMessage() {
return " " + nsb.toString();
}
public MyBean() {
}
}
NewSessionBean.java
@Stateless
@LocalBean
public class NewSessionBean {
}
In order to get the errors, just load the web page, add a space in the message string, save the java file (having the auto deployment toggled, otherwise redeploy manually).
Some exceptions
EJB5014: Exception resolving object
java.lang.NullPointerException at
com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate$SerializableLocalObjectDelegate.createObject(EJBLocalObjectInvocationHandlerDelegate.java:158)
IOException while loading persisted sessions: java.io.IOException
java.io.IOException
at com.sun.ejb.base.io.EJBObjectInputStream.resolveObject(EJBObjectInputStream.java:114)
UPDATE
If I replace the ManagedBean annotations with Named, therefore using CDI, and consequently replace javax.faces.bean.SessionScoped with javax.enterprise.context.SessionScoped, I have exactly the same problem when undeploying, and afterwords the application runs smoothly.
The thrown exception is exactly the same as before.
Your server tries to serialize and save http session. Your session beans should me serializable to make session persistence available. Ir looks like this reference : NewSessionBean nsb; is not serializable. You can make it transient and you should get rid of error. But after sesson restore nsb will be null. I’m not sure how it’s handled in EJB but this reference must be reinjected somehow.