code: public T findOneByAttribute(String attribute, Object value) {
          CriteriaBuilder cb = getEntityManager().getCriteriaBuilder();
          CriteriaQuery<T> query = cb.createQuery(getEntityClass());
          Root<T> from = query.from(getEntityClass());
  
          query.where(cb.equal(from.get(attribute), value));
  
          try {
              return getEntityManager().createQuery(query).getSingleResult();
          } catch (NoResultException e) {
              return null;
          }
      }
docs: Finds an entity by a given attribute. Returns null if none was found.
  
  @param attribute the attribute to search for
  @param value the value
  @return the entity or null if none was found