2

我尝试使用禁用有状态会话 bean 的钝化

@CacheConfig(maxSize = 0, idleTimeoutSeconds = 0)

http://docs.jboss.org/ejb3/docs/reference/1.0.7/html/SessionBean_and_MDB_configuration.html

我向我的有状态会话 bean 和它注入的托管 bean 添加了几个打印语句,以便更好地了解正在发生的事情。看起来有状态 bean 确实被注入到托管 bean 中(因为它不是 null),但是调用它的方法没有效果(如果您查看下面托管 bean 的 loadData() 方法,它会调用 test() 例程有状态会话 bean,但输出“test”从未出现)。

15:06:07,861 INFO [STDOUT] loadData programSlug = some-program-name

15:06:07,876 INFO [STDOUT] programServiceBean = 端点 [ jboss.j2ee:jar=TEI.war,name=ProgramServiceBean,service=EJB3 ] 和会话 43h1h2v-j35uon-h18czgvf-1-h18d0nzj-df 的无接口视图

15:06:07,908 错误 [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/TEI].[Faces Servlet]] Servlet.service() for servlet Faces Servlet 抛出异常:java .lang.IllegalStateException:无法在 org.hibernate.ejb.metamodel.AbstractAttribute.readObject(AbstractAttribute.java:122) [:3.6.6.Final] 处找到成员 [com.ray.TEI.model.Program#urlSlug] sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_30] 在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_30]

这是我的有状态会话 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();
  }
}

这是托管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
}

知道问题是什么吗?

谢谢,杰森

(顺便说一下,我使用的是 JBoss 6.1 Final)

4

1 回答 1

2

通过将 bean 删除超时设置为小于此处所述的空闲超时来解决我的问题https://community.jboss.org/wiki/Ejb3DisableSfsbPassivation(选项 2,方法 2)

import org.jboss.ejb3.annotation.CacheConfig;

@Stateful
@CacheConfig (maxSize=100000, idleTimeoutSeconds=600, removalTimeoutSeconds=300)
public class ProgramServiceBean {
  //...
}
于 2012-04-21T15:02:24.737 回答