I tried to deactivate passivation of a stateful session bean using
@CacheConfig(maxSize = 0, idleTimeoutSeconds = 0)
http://docs.jboss.org/ejb3/docs/reference/1.0.7/html/SessionBean_and_MDB_configuration.html
I added a couple print statements to my stateful session bean and the managed bean that it’s injected into to better understand what’s happening. It appears that the stateful bean is indeed injected into the managed bean (as it’s not null), but calling it’s methods has no effect (if you look at the loadData() method of the managed bean below, it calls the test() routine of the stateful session bean, but the output “test” never appears).
15:06:07,861 INFO [STDOUT] loadData programSlug = some-program-name
15:06:07,876 INFO [STDOUT] programServiceBean = No-Interface view for endpoint [ jboss.j2ee:jar=TEI.war,name=ProgramServiceBean,service=EJB3 ] and session 43h1h2v-j35uon-h18czgvf-1-h18d0nzj-df
15:06:07,908 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/TEI].[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception: java.lang.IllegalStateException:
Unable to locate member [com.ray.TEI.model.Program#urlSlug]
at org.hibernate.ejb.metamodel.AbstractAttribute.readObject(AbstractAttribute.java:122) [:3.6.6.Final]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_30]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_30]
Here is my stateful session bean…
package com.ray.TEI.ejb;
import com.ray.TEI.model.Program;
import javax.ejb.Stateful;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import org.jboss.ejb3.annotation.CacheConfig;
@Stateful
@CacheConfig(maxSize = 0, idleTimeoutSeconds = 0)
public class ProgramServiceBean {
@PersistenceContext(unitName="TEI", type=PersistenceContextType.EXTENDED)
protected EntityManager em;
public void test() {
System.out.println("test");
}
public Program findBySlug(String urlSlug) {
System.out.println("findBySlug " + urlSlug);
return em.createNamedQuery("Program.findBySlug", Program.class)
.setParameter("urlSlug", urlSlug)
.getSingleResult();
}
}
And here is the managed bean…
package com.ray.TEI.controller;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import com.ocpsoft.pretty.faces.annotation.URLAction;
import com.ocpsoft.pretty.faces.annotation.URLMapping;
import com.ocpsoft.pretty.faces.annotation.URLQueryParameter;
import com.ray.TEI.ejb.ProgramServiceBean;
import com.ray.TEI.model.Program;
@Named
@RequestScoped
@URLMapping(
id="uuts",
pattern="/#{programSlug:uutsController.programSlug}/uuts",
viewId="/uuts.xhtml"
)
public class UutsController {
@Inject private ProgramServiceBean programServiceBean;
private String programSlug;
private Program program;
@URLQueryParameter("new")
private Boolean displayAddForm = false;
@URLAction
public String loadData() {
System.out.println("loadData programSlug = " + programSlug);
if (programSlug != null) {
System.out.println("programServiceBean = " + programServiceBean);
programServiceBean.test();
program = programServiceBean.findBySlug(programSlug);
System.out.println("loadData program = " + program.getName());
}
if (program == null) {
return "pretty:error";
}
return null;
}
public String getProgramSlug() {
return programSlug;
}
public void setProgramSlug(String programSlug) {
this.programSlug = programSlug;
}
//other getters/setters
}
Any idea of what the problem is?
Thanks,
Jason
(By the way, I’m using JBoss 6.1 Final)
Fixed my problem by setting the bean removal timeout to be less than the idle timeout as described here https://community.jboss.org/wiki/Ejb3DisableSfsbPassivation (Option 2, method 2)