code: public static PrincipalUser findByUserName(EntityManager em, String userName) {
          Class<PrincipalUser> type = PrincipalUser.class;
          TypedQuery<PrincipalUser> query = em.createNamedQuery("PrincipalUser.findByUserName", type);
  
          try {
              return query.setParameter("userName", userName).getSingleResult();
          } catch (NoResultException ex) {
              return null;
          }
      }
docs: Finds the application database user account for the provided user name.
  
  @param   em        The entity manager to use.
  @param   userName  The user name for which to retrieve the account information for.
  
  @return  The user account or null if no account exists.