非法参数异常引起的EJB调用期间发生系统异常

时间:2019-04-15 13:27:14

标签: jpa jsf

我不太确定这是怎么回事。它继续显示这些错误消息。似乎有一些空值,但我似乎无法识别和纠正这些问题。有人可以帮忙看看吗?

更新:我认为该问题应该在managedbean或后构造方法中,但我似乎找不到原因。

摘要错误消息

System exception occurred during an invocation on EJB RequestController, 
method: public entity.Request ejb.session.stateless.RequestController.retrieveRequestByRequestId(java.lang.Long) throws exception.RequestNotFoundException

Caused by: java.lang.IllegalArgumentException: An instance of a null PK has been incorrectly provided for this find operation.

DeleteRequestManagedBean中的后构造

@PostConstruct
public void postConstruct() {

    requestId = (Long)FacesContext.getCurrentInstance().getExternalContext().getFlash().get("request");
    try {
        request = requestControllerLocal.retrieveRequestByRequestId(requestId);
    }
//Removed some irrelevant codes

在DeleteRequestManagedBean中删除请求方法

public void deleteRequest() {

    requestControllerLocal.deleteRequest(requestId); 
    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "Request has been successfully deleted: ", null));
}

用于删除xhtml中请求的按钮

<p:commandButton value="Remove" icon ="fa fa-fw fa-remove" styleClass="p-btnDelete" actionListener="#{deleteRequestManagedBean.deleteRequest}"/>

在RequestController(无状态Sessionbean)中删除请求方法

@Override
public void deleteRequest(Long requestId) throws RequestNotFoundException, DeleteRequestException {
//Removed some irrelevant codes
Request requestToDelete = retrieveRequestByRequestId(requestId);
requestToDelete.getCategory().getRequests().remove(requestToDelete);
        em.remove(requestToDelete);
}

如果您需要其他信息,请随时告诉我。谢谢!

1 个答案:

答案 0 :(得分:0)

事实证明,我的Managedbean和xhtml页面都有问题。

我必须改用 getAttribute()并从xhtml页面获取属性“ postRToDelete”。在没有获取此信息的情况下,它继续为我提供了空指针,非法参数异常。

在这里对那些犯了与我相同的错误的人有益。

DeleteRequestManagedbean

Request request = (Request) event.getComponent().getAttributes().get("postRToDelete");

xhtml页面

<p:commandButton value="Delete" icon ="fa fa-fw fa-remove" styleClass="p-btnDelete" actionListener="#{profileManagedBean.deletePostedRequest}" update="@form">

<!--attribute from here-->
<f:attribute name="postRToDelete" value="#{postedReq}"/>
</p:commandButton>