title: NoResultException: getSingleResult() did not retrieve any entities. QueryImpl.throwNoResultException
body: <p>We have a java web application deployed into payara 164 application Server.<br>
  Host machine is a debian 9.3 server, used database is a mariadb-server-10.1, java version is "1.8.0_131". </p>
  
  <p>Recently we are facing some problems among which the one below. It is just an instance since it happens randomly with a lot of other Objects even though indeed they are not NULL but correctly populated. </p>
  
  <blockquote>
    <p>javax.ejb.EJBTransactionRolledbackException at <strong>dmlm.models.entities.User.getCustomer(User.java:337)</strong>
    Caused by: javax.persistence.NoResultException: getSingleResult() did not retrieve any entities.</p>
  </blockquote>
  
  <p>EDIT:</p>
  
  <p>in several place is called the following method:</p>
  
  <pre><code>public Customer getCustomerByUser(User user)
  {
      TypedQuery&lt;Customer&gt; q = em.createNamedQuery("Customer.findByUser", Customer.class);
      q.setParameter("userId", user.getId());
      if (LOG.isLoggable(Level.FINER)) {
          //&lt;editor-fold defaultstate="collapsed" desc="per stampare nei log una query runtime"&gt;
          org.eclipse.persistence.sessions.Session session
                  = em.unwrap(JpaEntityManager.class).getActiveSession();
          DatabaseQuery databaseQuery = ((EJBQueryImpl) q).getDatabaseQuery();
          databaseQuery.prepareCall(session, new DatabaseRecord());
          DatabaseRecord recordWithValues = new DatabaseRecord();
          recordWithValues.add(new DatabaseField("userId"), user.getId());
  
          String sqlStringWithArgs
                  = databaseQuery.getTranslatedSQLString(session, recordWithValues);
          LOG.finest(sqlStringWithArgs);
          //&lt;/editor-fold&gt;
      }
      return q.getSingleResult();
  }
  </code></pre>
  
  <p>the log part is just to print out the real query created with parameter</p>
  
  <p>the named query: </p>
  
  <pre><code>@NamedQuery(name = "Customer.findByUser",
              query = "SELECT m FROM Customer m JOIN m.users us WHERE m.deleted = false AND us.id = :userId")
  </code></pre>
  
  <p>As said, the result should be a single result with customer id</p>
  
  <p>EDIT 2:
  We have tried to change the db from maria-db to mysql, with no success</p>