ParameterElementDAOImpl extends AbstractJPADAO<ParameterElement, Long> implements
        ParameterElementDAO { @Override public ParameterElement findParameterElementFromCode(String parameterElementCode) { Query query = entityManager.createQuery("SELECT pe FROM " + getEntityClass().getName() + " pe" + " WHERE pe.parameterElementCode = :parameterElementCode"); query.setParameter("parameterElementCode", parameterElementCode); try { return (ParameterElement) query.getSingleResult(); } catch (NoResultException nre) { return null; } catch (NonUniqueResultException nure) { return null; } }  @Override ParameterElement findParameterElementFromCode(String parameterElementCode);  }
@Test public void testFindParameterElementFromCode() { assertEquals(Long.valueOf(1),parameterElementDAO.findParameterElementFromCode("PARAM_EL_1").getId()); assertEquals(Long.valueOf(2),parameterElementDAO.findParameterElementFromCode("PARAM_EL_2").getId()); assertNull(parameterElementDAO.findParameterElementFromCode("PARAM_EL_3")); }