title: <f:viewParam> javax.persistence.NoResultException: No entity found for query
body: <p>I have a grid where the user can see his records, when he clicks on a record it links to another page so he can edit or delete it.</p>
  
  <p>The record in that page shows correctly, and it has a button to update the record if any changes where made and getting the user back to the grid.</p>
  
  <p>I am working with Java 1.8 with Primefaces, on Netbeans 8.0.2 and wildfy 8.2 and my OS is UBUNTU.</p>
  
  <p>When I try to change something, the pages just does nothing and I have this record in the wildfly log </p>
  
  <blockquote>
    <p>15:11:16,369 ERROR [org.jboss.as.ejb3] (default task-19)
    javax.ejb.EJBTransactionRolledbackException: No entity found for query
    15:11:16,371 ERROR [org.jboss.as.ejb3.invocation] (default task-19)
    JBAS014134: EJB Invocation failed on component GastoDAOImpl for method
    public abstract dominio.Gasto
    persistencia.GastoDAO.getGastoporID(int):
    javax.ejb.EJBTransactionRolledbackException: No entity found for query</p>
    
    <p>Caused by: javax.persistence.NoResultException: No entity found for
    query</p>
    
    <blockquote>
      <p>15:11:16,405 ERROR [org.jboss.as.ejb3.invocation] (default task-19)
      JBAS014134: EJB Invocation failed on component GastoControladorImpl
      for method public abstract dominio.Gasto
      controladores.GastoControlador.obtenerGastoporID(int):
      javax.ejb.EJBTransactionRolledbackException: No entity found for query</p>
      
      <p>15:11:16,439 SEVERE
      [javax.enterprise.resource.webcontainer.jsf.context] (default task-19)
      javax.faces.component.UpdateModelException: javax.el.ELException:
      /editargastos.xhtml @10,64 value="#{gastoBean.idGasto}":
      javax.ejb.EJBTransactionRolledbackException: No entity found for query</p>
    </blockquote>
  </blockquote>
  
  <p>The weird thing is that if I run the program in debug mode, there are no problems at all and the system just works as intended (the data is properly modified and the user just gets back to the main grid.</p>
  
  <p>My code:</p>
  
  <p>1) This is the page that shows the record for the item that will be modified
   it shows the correct record in debug mode or normal mode</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://xmlns.jcp.org/jsf/html"
        xmlns:f="http://xmlns.jcp.org/jsf/core"
        xmlns:p="http://primefaces.org/ui"
        xmlns:ui="http://xmlns.jcp.org/jsf/facelets"&gt;
      &lt;h:head&gt;
          &lt;f:metadata&gt;
              &lt;f:viewParam name="id_gasto" value="#{gastoBean.idGasto}"/&gt;
          &lt;/f:metadata&gt;
  
          &lt;title&gt;Gaston editar un gasto&lt;/title&gt;
      &lt;/h:head&gt;
      &lt;h:body&gt;
          &lt;div id="header"&gt;
              &lt;ui:insert name="header"&gt;
                  &lt;ui:include src="defaultHeader.xhtml" /&gt;
              &lt;/ui:insert&gt;  
          &lt;/div&gt;
  
          &lt;h2&gt;Editar un gasto  Propietario: #{loginBean.usuario.apellido}&lt;/h2&gt;
          &lt;h3&gt;Familia: #{loginBean.usuario.familia.nombre}&lt;/h3&gt;
  
          &lt;h:form&gt;
              &lt;h:messages&gt;&lt;/h:messages&gt;
              &lt;p:panelGrid columns="2"&gt;
                  &lt;h:outputText value=" Fecha de pago" /&gt;     
                  &lt;p:calendar value="#{gastoBean.gasto.fecha_registro}" required="true"/&gt;
                  &lt;h:outputText value=" Moneda" /&gt;     
                  &lt;h:selectOneMenu id="moneda" value="#{gastoBean.gasto.moneda}" &gt;
                      &lt;f:selectItems value="#{gastoBean.monedas}"&gt;&lt;/f:selectItems&gt;
                  &lt;/h:selectOneMenu&gt;
                  &lt;h:outputText value="Monto" /&gt;   
                  &lt;h:inputText value="#{gastoBean.gasto.monto}" required="true"/&gt;
                  &lt;h:outputText value=" Descripcion" /&gt;     
                  &lt;h:inputText value="#{gastoBean.gasto.descripcion}" required="true"/&gt;
                  &lt;h:outputText value=" Clasificacion" /&gt;     
                  &lt;h:inputText value="#{gastoBean.gasto.clasificacion}" required="true"/&gt;
  
              &lt;/p:panelGrid&gt;
              &lt;br&gt;&lt;/br&gt;
  
              &lt;p:commandButton action="#{gastoBean.modificarGasto()}" value="Modificar gasto" /&gt;
              &lt;p:commandButton action="#{gastoBean.eliminarGasto(id_gasto)}" value="Eliminar gasto" /&gt;
  
              &lt;br&gt;&lt;/br&gt;
              &lt;h:outputText value="#{gastoBean.mensaje}"  /&gt;
              &lt;br&gt;&lt;/br&gt;&lt;br&gt;&lt;/br&gt;
              &lt;hr&gt;&lt;/hr&gt;
              &lt;small&gt;Todos los campos son obligatorios&lt;/small&gt;
          &lt;/h:form&gt;
      &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>2) Backing bean: This is the bean called by the modify item in the previous page, when the systems runs in debug mode I can see that every single line works as intended and after completition the database is updated and the user is send to the  grid.</p>
  
  <p>But... if I run the program without the debug option it just not work at all, nor database modification, nor user redirection and nor exception is shown.</p>
  
  <pre><code>public void modificarGasto() {
      try {
          controlador.modificarGasto(gasto);
          Familia f = this.autenticado.getUsuario().getFamilia();
          this.listaGastos = controlador.obtenerGastosFamiliaporID(f.getId_familia());
          ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
  
          ec.redirect("listadog.xhtml");
      } catch (Exception e) {
          this.mensaje = "ERROR: No se pudo guardar el registro";
      }
  }
  </code></pre>
  
  <p>UPDATE: I just modified the method attached to the the button just to give a message and that wont work neither in "normal mode" I am staring to think it is actually an error in Primefaces :(</p>