2011-10-17 31 views
4

QuestionCommonBusiness無法ejbRef轉換爲EJB

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豆)......我不知道我這個正確使用

@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 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 [email protected]

root cause 

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

com.myapp.interfaces.QuestionController.initialize()上 [email protected]

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. 
+1

它的工作,如果你使用'@ EJB',而不是'@ Inject'?而如果你把'@ Local'放在界面上而不是具體的實現上呢? – BalusC

+0

它在我更改(@)時注入到JSF bean中的(@)EJB中。我在WEB-INF文件夾中使用beans.xml,在其餘項目中使用META-INF(EJB項目,JPA項目...使用Eclipse嚮導) – LuckyLuke

+0

那麼,這將是另一個Weld bug 。在你的情況下,'@ Local'選擇了錯誤的接口。看起來像這樣:http://java.net/jira/browse/GLASSFISH-16186 – BalusC

回答

5

這個問題與Glassfish Weld issue 16186有關。錯誤的界面被挑選爲@Local,即最接近的界面。

您已經2種選擇:

  1. 只需使用@EJB代替。
  2. 擺脫QuestionCommonBusiness超級界面。

不用說,選項1是首選。

1

或者你可能包括QuestionCommonBusiness.class在@Local註釋:

@Stateless 
    @Local({QuestionLocalBusiness.class, QuestionCommonBusiness.class) 
    public class QuestionManagerEJB implements QuestionLocalBusiness { 
     ... 
相關問題