Strony

2017-01-11

EntityManager - find list of objects with handled NoResultException

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

        try {
            return em.createNamedQuery(Element.FIND_ALL_BY_TASK, Element.class)
                    .setParameter("task", task)
                    .getResultList();
        } catch (NoResultException e) {
            logger.info(ELEMENT_NOT_FOUND_MSG);

            return Collections.emptyList();
        }
}

Brak komentarzy:

Prześlij komentarz