2017-04-26 32 views
0

我面对试图调用在啊显示的列表中的每一项bean方法时,一个问题一个bean的方法:数据表,我得到的folwing例外:呼吁每个数据表项

- INFOS: Exception when handling error trying to reset the response. javax.persistence.NoResultException: No entity found for query 
at org.hibernate.jpa.internal.QueryImpl.getSingleResult(QueryImpl.java:498) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 

我有一个帐户实体和部门实体,它们有一个名为代码的公共列,但它们没有链接,因此为了显示与帐户相同代码的部门,我使用此共享属性(代码)根据帐户的代码获取部门。

<h:form prependId="false"> 
    <h:dataTable id="accounts_list" class="table table-bordered table-striped table-hover table-condensed" 
    var="account" value="#{AccountBean.accountProvider.allAccounts}"> 
     <h:column> 
     <f:facet name="header"> 
      <h:outputText value="account type"/> 
     </f:facet> 
     <h:outputText value="#{account.categoy.label}"/> 
     </h:column> 
     <h:column> 
     <f:facet name="header"> 
      <h:outputText value="account code"/> 
     </f:facet> 
     <h:outputText value="#{account.code}"/> 
     </h:column> 
     <h:column> 
     <f:facet name="header"> 
      <h:outputText value=" department"/> 
     </f:facet> 
     <h:outputText value="#{AccountBean.searchDepByAccountCode(account.code)}"/> 
     </h:column> 
         ..... 
    </h:dataTable> 
</h:form> 

是否可以继续这样做,或者我应该寻找另一种解决方案来做到这一点。

谢谢,

+0

这是业务逻辑的一部分。如果没有这样的部门,你应该怎么做?你可以例如捕获异常并在searchDepByAccountCode()方法中返回空字符串或“not found”字符串。你应该先决定。 – StanislavL

+0

谢谢,这是问题的理念,我已经检查使用SQL,但似乎像数据改变,因为,通过一个简单的尝试赶上解决了这个问题 – abbr

回答

0

这是业务逻辑的一部分。如果没有这样的部门,你应该怎么做?你可以例如捕获异常并在searchDepByAccountCode()方法中返回空字符串或“not found”字符串。

或者,您可以返回不是单个结果,而是一个detaartment列表。该列表可以是空的,包含一个或多个项目。