ProductDao extends HibernateDao<Product, Long> { public List<Product> getNoCollectionProducts (User user) { ArrayList<Product> products = new ArrayList<> (); StringBuilder sqlBuilder = new StringBuilder (); sqlBuilder.append ("SELECT p.ID "); sqlBuilder.append ("FROM PRODUCTS p "); sqlBuilder.append ("LEFT OUTER JOIN COLLECTION_PRODUCT cp ") .append ("ON p.ID = cp.PRODUCTS_ID "); sqlBuilder.append ("WHERE cp.COLLECTIONS_UUID IS NULL"); final String sql = sqlBuilder.toString (); List<BigInteger> queryResult = getHibernateTemplate ().execute ( new HibernateCallback<List<BigInteger>> () { @Override @SuppressWarnings ("unchecked") public List<BigInteger> doInHibernate (Session session) throws HibernateException, SQLException { SQLQuery query = session.createSQLQuery (sql); return query.list (); } }); for (BigInteger pid : queryResult) { Product p = read (pid.longValue ()); if (p == null) { throw new IllegalStateException ( "Existing product is null ! product id = " + pid.longValue ()); } products.add (p); } return products; }  static int getMaxPageSize(); Product getProductByPath(final URL path); @Override List<Product> listCriteria(DetachedCriteria detached, int skip,
         int top); @SuppressWarnings ("unchecked") List<Product> read(List<Long>ids); boolean exists(URL url); @Override List<Product> scroll(String clauses, int skip, int n); Iterator<Product> scrollFiltered(String filter, final Long collection_id, int skip); int count(String filter, final String collection_uuid); @Override void deleteAll(); @Override void delete(Product product); void setIndexes(Product product, List<MetadataIndex>indexes); void setIndexes(Long id, List<MetadataIndex>indexes); Iterator<Product> getProductsByIngestionDate(Date max_date); Iterator<Product> getProductsLowerAccess(Date max_date); static String getPathFromProduct(Product product); static String getPathFromURL(URL product); @SuppressWarnings ("unchecked") List<Long> getAuthorizedProducts(String user_uuid); @SuppressWarnings ("unchecked") Product getProductByDownloadableFilename(final String filename,
         final Collection collection); Product getProductByUuid(String uuid); List<Product> getNoCollectionProducts(User user); List<Product> scrollUploadedProducts(final User user, final int skip,
      final int top); @SuppressWarnings ("unchecked") List<Product> getUploadedProducts(final User user); User getOwnerOfProduct(final Product product); boolean isAuthorized(final String user_uuid, final long product_id); Iterator<Product> getUnprocessedProducts(); Iterator<Product> getAllProducts(); Product getProductByIdentifier(String identifier);  }
@Test public void getNoCollectionProducts () { String uid = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa0"; long expectedPid1 = 6; long expectedPid2 = 7; List<Product> products = dao.getNoCollectionProducts (emulateUser (uid, "koko")); Assert.assertEquals (products.size (), 2); Assert.assertEquals (products.get (0).getId ().intValue (), expectedPid1); Assert.assertEquals (products.get (1).getId ().intValue (), expectedPid2); }