CollectionDao extends HibernateDao<Collection, String> { @SuppressWarnings ("unchecked") public List<Collection> getCollectionsOfProduct (final Long product_id) { return getHibernateTemplate().execute(session -> { String hql = "select c from Collection c " + "left outer join c.products p where p.id = ? ORDER BY c.name"; Query query = session.createQuery(hql); query.setFetchSize(10_000); query.setParameter(0, product_id, StandardBasicTypes.LONG); return (List<Collection>) query.list(); }); }  @Override void delete(final Collection collection); @Override void deleteAll(); boolean contains(final String cid, final Long pid); void removeProduct(final String cid, final Long pid, User user); void removeProducts(final String cid, final Long[] pids, User user); @SuppressWarnings ("unchecked") List<Collection> getCollectionsOfProduct(final Long product_id); List<Long> getProductIds(final String collection_uuid, User user); @SuppressWarnings("unchecked") List<String> getCollectionsUUID(); String getCollectionUUIDByName(final String collection_name); Collection getByName(final String name); Iterator<Collection> getAllCollections(); final static String HIDDEN_PREFIX; final static String COLLECTION_ROOT_NAME; }
@Test public void getCollectionsOfProduct () { long pid = 1; List<Collection> collections = dao.getCollectionsOfProduct (pid); Assert.assertNotNull (collections); Assert.assertEquals (collections.size (), 3); Assert.assertTrue (collections.contains (dao.read ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1"))); Assert.assertTrue (collections.contains (dao.read ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa3"))); Assert.assertTrue (collections.contains (dao.read ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa4"))); }