UserDAO extends AbstractJPADAO<User, Long> { public User read(Long key) { if (key == null) { return null; } Query query = entityManager.createQuery("SELECT u FROM " + getEntityClass().getName() + " u" + " left join fetch u.contractSet c" + " WHERE u.id = :id"); query.setParameter("id", key); 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 testRead(){ User user = userDAO.read(1L); assertEquals("Test1", user.getName()); assertEquals("Role1", user.getRole().getRoleName()); user = userDAO.read(2L); assertEquals("Test2", user.getName()); assertEquals("Role2", user.getRole().getRoleName()); }