Strony

2017-01-11

EntityManager - find list of objects

public List<Element> findAllElements(Task task) {
    logger.info("Try to find elements - task: {}", task.getId());

    return em.createNamedQuery(Element.FIND_ALL_BY_TASK, Element.class)
               .setParameter("task", task)
               .getResultList();
}

2 komentarze:

  1. getResultList method doesn't throw NoResultException, instead it returns empty list.

    OdpowiedzUsuń
  2. Yes, You are right - getSingleResult throws NoResultException. I changed this example. Thank You!

    OdpowiedzUsuń