WebResourceDAOImpl extends AbstractJPADAO<WebResource, Long> implements WebResourceDAO { @Override @SuppressWarnings("unchecked") public WebResource findByUrlAndParentWebResource(String url, WebResource webResource) { Query query = entityManager.createQuery( "SELECT wr FROM " + PageImpl.class.getName() + " wr" + " WHERE wr.url = :url" + " AND wr.parent =:webResource"); query.setParameter("url", url); query.setParameter("webResource", webResource); try { return (WebResource) query.getSingleResult(); } catch (NoResultException nre) { return null; } catch (NonUniqueResultException nure) { List<WebResource> queryResult = query.getResultList(); for (WebResource wr : queryResult) { if (StringUtils.equals(wr.getURL(),url)) { return wr; } } return null; } } WebResourceDAOImpl(); @Override @SuppressWarnings("unchecked") WebResource findByUrl(String url); @Override @SuppressWarnings("unchecked") WebResource findByAuditAndUrl(Audit audit, String url); @Override @SuppressWarnings("unchecked") WebResource read(Long key); @Override @SuppressWarnings("unchecked") WebResource findByUrlAndParentWebResource(String url, WebResource webResource); @Override @SuppressWarnings("unchecked") List<WebResource> findWebResourceFromItsParent(
            WebResource webResource,
            int start,
            int chunkSize); @Override @SuppressWarnings("unchecked") Long findNumberOfChildWebResource(WebResource webResource); @Override @SuppressWarnings("unchecked") WebResource ligthRead(Long webResourceId); @Override Long findParentWebResourceId(Long webresourceId); @Override Long findChildWebResourceCount(WebResource parentWebResource);  }
@Test public void testFindByUrlAndParentWebResource(){ WebResource parentWr = webresourceDAO.read(Long.valueOf(1)); WebResource wr = webresourceDAO.findByUrlAndParentWebResource(URL2, parentWr); assertEquals(Long.valueOf(2), wr.getId()); wr = webresourceDAO.findByUrlAndParentWebResource(URL1, parentWr); assertNull(wr); }