ProductCartDao extends HibernateDao<ProductCart, String> { public void deleteProductReferences(final Product product) { getHibernateTemplate().execute(new HibernateCallback<Void>() { @Override public Void doInHibernate(Session session) throws HibernateException, SQLException { session.createSQLQuery("DELETE FROM CART_PRODUCTS p WHERE p.PRODUCT_ID = :pid") .setParameter("pid", product.getId()).executeUpdate(); return null; } }); }  @SuppressWarnings("unchecked") ProductCart getCartOfUser(final User user); void deleteCartOfUser(User user); void deleteProductReferences(final Product product); List<Product> scrollCartOfUser(final User user, final int skip, final int top); List<Long> getProductsIdOfCart(User user);  }
@Test public void deleteProductReferences() { Product product = new Product(); product.setId(5L); dao.deleteProductReferences(product); List<ProductCart> pcs = dao.readAll(); for (ProductCart pc: pcs) { assertFalse(pc.getProducts().contains(product)); } }