无法将 ejbRef 转换为 ejb

发布于 2024-12-10 13:22:04 字数 2680 浏览 0 评论 0原文

QuestionCommonBusiness

public interface QuestionCommonBusiness {

    void create(Question question);
    void update (Question question);
    void delete(Question question);
    Question read(Integer id);

    List<Question> all();
}

QuestionLocalBusiness

public interface QuestionLocalBusiness extends QuestionCommonBusiness {

}

QuestionManagerEJB

@Stateless
@Local(QuestionLocalBusiness.class)
public class QuestionManagerEJB implements QuestionLocalBusiness {

    @PersistenceContext(unitName = "MyPU")
    private EntityManager entityManager;

    @Override
    public void create(Question question) {
        entityManager.persist(question);
    }

    @Override
    public void update(Question question) {
        entityManager.merge(question);
    }

    @Override
    public void delete(Question question) {
        entityManager.remove(question);
    }

    @Override
    public Question read(Integer id) {
        return entityManager.find(Question.class, id);
    }

    @Override
    public List<Question> all() {

        TypedQuery<Question> query = entityManager.createNamedQuery(
                "allQuestions", Question.class);
        return query.getResultList();
    }
}

QuestionController(JSF bean)...我不知道我是否正确使用了它

 @Named
    @RequestScoped
    public class QuestionController {

    @Inject
    private QuestionLocalBusiness questionManager;

    private List<Question> questions;

    @PostConstruct
    public void initialize() {
        questions = questionManager.all();
    }

    public List<Question> getQuestions() {
        return questions;
    }

}

<强>错误

HTTP 状态 500 -

类型异常报告

信息

描述服务器遇到内部错误(),导致其无法完成此请求。

例外

javax.servlet.ServletException:WELD-000049无法调用[方法] @PostConstruct public

com.myapp.interfaces.QuestionController.initialize() 上 com.myapp.interfaces.QuestionController@29421836

根本原因

org.jboss.weld.exceptions.WeldException: WELD-000049 无法调用 [方法] @PostConstruct public

com.myapp.interfaces.QuestionController.initialize() 上 com.myapp.interfaces.QuestionController@29421836

根本原因

java.lang.reflect.InitationTargetException

根本原因

java.lang.IllegalStateException:无法将 ejb QuestionManagerEJB 的 ejbRef 转换为接口类型的业务对象

com.myapp.application.QuestionCommonBusiness

note GlassFish Server 开源版 3.1.1 日志中提供了异常的完整堆栈跟踪及其根本原因。

QuestionCommonBusiness

public interface QuestionCommonBusiness {

    void create(Question question);
    void update (Question question);
    void delete(Question question);
    Question read(Integer id);

    List<Question> all();
}

QuestionLocalBusiness

public interface QuestionLocalBusiness extends QuestionCommonBusiness {

}

QuestionManagerEJB

@Stateless
@Local(QuestionLocalBusiness.class)
public class QuestionManagerEJB implements QuestionLocalBusiness {

    @PersistenceContext(unitName = "MyPU")
    private EntityManager entityManager;

    @Override
    public void create(Question question) {
        entityManager.persist(question);
    }

    @Override
    public void update(Question question) {
        entityManager.merge(question);
    }

    @Override
    public void delete(Question question) {
        entityManager.remove(question);
    }

    @Override
    public Question read(Integer id) {
        return entityManager.find(Question.class, id);
    }

    @Override
    public List<Question> all() {

        TypedQuery<Question> query = entityManager.createNamedQuery(
                "allQuestions", Question.class);
        return query.getResultList();
    }
}

QuestionController (JSF bean)...I don't know if I use this correctly

 @Named
    @RequestScoped
    public class QuestionController {

    @Inject
    private QuestionLocalBusiness questionManager;

    private List<Question> questions;

    @PostConstruct
    public void initialize() {
        questions = questionManager.all();
    }

    public List<Question> getQuestions() {
        return questions;
    }

}

Error

HTTP Status 500 -

type Exception report

message

descriptionThe server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: WELD-000049 Unable to invoke [method] @PostConstruct public

com.myapp.interfaces.QuestionController.initialize() on
com.myapp.interfaces.QuestionController@29421836

root cause

org.jboss.weld.exceptions.WeldException: WELD-000049 Unable to invoke [method] @PostConstruct public

com.myapp.interfaces.QuestionController.initialize() on
com.myapp.interfaces.QuestionController@29421836

root cause

java.lang.reflect.InvocationTargetException

root cause

java.lang.IllegalStateException: Unable to convert ejbRef for ejb QuestionManagerEJB to a business object of type interface

com.myapp.application.QuestionCommonBusiness

note The full stack traces of the exception and its root causes are available in the GlassFish Server Open Source Edition 3.1.1 logs.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

从此见与不见 2024-12-17 13:22:04

此问题与 Glassfish Weld 问题 16186 相关。 @Local 选择了错误的接口,即最上层接口。

您有 2 个选择:

  1. 只需使用 @EJB 即可。
  2. 摆脱 QuestionCommonBusiness 超级接口。

不用说,选项 1 是首选。

This issue is related to Glassfish Weld issue 16186. The wrong interface is been picked for @Local, namely the supermost interface.

You've 2 options:

  1. Just use @EJB instead.
  2. Get rid of the QuestionCommonBusiness superinterface.

Needless to say that option 1 is preferred.

三生一梦 2024-12-17 13:22:04

或者您可以在 @Local 注释中包含 QuestionCommonBusiness.class:

   @Stateless
   @Local({QuestionLocalBusiness.class, QuestionCommonBusiness.class)
   public class QuestionManagerEJB implements QuestionLocalBusiness {
      ...

Or you may include QuestionCommonBusiness.class in your @Local annotation:

   @Stateless
   @Local({QuestionLocalBusiness.class, QuestionCommonBusiness.class)
   public class QuestionManagerEJB implements QuestionLocalBusiness {
      ...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文