Невозможно конвертировать ejbRef для ejb - PullRequest
4 голосов
/ 17 октября 2011

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;
    }

}

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 () в 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 () в 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.

Ответы [ 2 ]

5 голосов
/ 18 октября 2011

Эта проблема связана с выпуском Glassfish Weld 16186 .Для @Local выбран неправильный интерфейс, а именно самый верхний интерфейс.

У вас есть 2 варианта:

  1. Просто используйте @EJB.
  2. Избавьтесь от суперинтерфейса QuestionCommonBusiness.

Нет необходимости говорить, что предпочтительным является вариант 1.

2 голосов
/ 15 апреля 2014

Или вы можете включить QuestionCommonBusiness.class в аннотацию @Local:

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