UserDAO extends AbstractJPADAO<User, Long> { public User findUserFromEmail(String email) { Query query = entityManager.createQuery("SELECT u FROM " + getEntityClass().getName() + " u" + " left join fetch u.contractSet c" + " WHERE u.email = :email"); query.setParameter("email", email); try { return (User)query.getSingleResult(); } catch (NoResultException e) { return null; } } UserDAO(); User read(Long key); User findUserFromEmail(String email); User findUserFromName(String name); boolean isAccountActivated(String email);  }
@Test public void testFindUserFromEmail(){ User user = userDAO.findUserFromEmail("test1@test.com"); assertEquals(Long.valueOf(1), user.getId()); assertEquals(2, user.getContractSet().size()); user = userDAO.findUserFromEmail("test@test.com"); assertNull(user); }