无法将 ejbRef 转换为 ejb
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@29421836root cause org.jboss.weld.exceptions.WeldException: WELD-000049 Unable to invoke [method] @PostConstruct public
com.myapp.interfaces.QuestionController.initialize() on
com.myapp.interfaces.QuestionController@29421836root 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
此问题与 Glassfish Weld 问题 16186 相关。
@Local
选择了错误的接口,即最上层接口。您有 2 个选择:
@EJB
即可。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:
@EJB
instead.QuestionCommonBusiness
superinterface.Needless to say that option 1 is preferred.
或者您可以在 @Local 注释中包含 QuestionCommonBusiness.class:
Or you may include QuestionCommonBusiness.class in your @Local annotation: