QuestionCommonBusiness
public interface QuestionCommonBusiness {
void create(Question question);
void update (Question question);
void delete(Question question);
Question read(Integer id);
List<Question> all();
}
Run Code Online (Sandbox Code Playgroud)
QuestionLocalBusiness
public interface QuestionLocalBusiness extends QuestionCommonBusiness {
}
Run Code Online (Sandbox Code Playgroud)
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();
}
}
Run Code Online (Sandbox Code Playgroud)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
错误
Run Code Online (Sandbox Code Playgroud)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 publicCom.myapp.interfaces.QuestionController.initialize()com.myapp.interfaces.QuestionController@29421836
Run Code Online (Sandbox Code Playgroud)root cause org.jboss.weld.exceptions.WeldException: WELD-000049 Unable to invoke [method] @PostConstruct publicCom.myapp.interfaces.QuestionController.initialize()com.myapp.interfaces.QuestionController@29421836
Run Code Online (Sandbox Code Playgroud)root cause java.lang.reflect.InvocationTargetException root cause java.lang.IllegalStateException: Unable to convert ejbRef for ejb QuestionManagerEJB to a business object of type interfacecom.myapp.application.QuestionCommonBusiness
Run Code Online (Sandbox Code Playgroud)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.
此问题与Glassfish焊接问题16186有关.选择了错误的接口@Local,即最外层的接口.
你有两个选择:
@EJB.QuestionCommonBusiness超级接口.不用说选项1是首选.
| 归档时间: |
|
| 查看次数: |
2799 次 |
| 最近记录: |