Reputation: 49097
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.
Upvotes: 4
Views: 2878
Reputation: 285
Or you may include QuestionCommonBusiness.class in your @Local annotation:
@Stateless
@Local({QuestionLocalBusiness.class, QuestionCommonBusiness.class)
public class QuestionManagerEJB implements QuestionLocalBusiness {
...
Upvotes: 2
Reputation: 1109222
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.
Upvotes: 5