ProductCategoryServiceImpl extends BaseGenericServiceImpl<ProductCategory> implements ProductCategoryService { @Override public void removeByCategoryProductIds(final long categoryId, final long productId) { getGenericDao().executeUpdate("REMOVE.PRODUCTCATEGORY.BY.CATEGORYID.PRODUCTID", categoryId, productId); } ProductCategoryServiceImpl(final GenericDAO<ProductCategory, Long> productCategoryDao); @Override ProductCategory findByCategoryIdProductId(final long categoryId, final long productId); @Override List<Long> getByProductId(final long productId); @Override List<ProductCategory> findByProductId(final long productId); @Override void removeByCategoryProductIds(final long categoryId, final long productId); @Override void removeByProductIds(final long productId); @Override int getNextRank(final long categoryId);  }
@Test public void testRemoveByCategoryProductIds() throws Exception { final GenericDAO<ProductCategory, Long> productCategoryDAO = (GenericDAO<ProductCategory, Long>) ctx().getBean("productCategoryDao"); final ProductCategoryService productCategoryService = (ProductCategoryService) ctx().getBean(ServiceSpringKeys.PRODUCT_CATEGORY_SERVICE); final long product1pk = 11000L; final long[] product1categorypk = new long[1]; getTxReadOnly().execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(final TransactionStatus transactionStatus) { final List<ProductCategory> pc = productCategoryDAO.findByCriteria( " where e.product.productId = ?1", product1pk); assertEquals(1, pc.size()); product1categorypk[0] = pc.get(0).getCategory().getCategoryId(); transactionStatus.setRollbackOnly(); } }); assertTrue(product1categorypk[0] > 0L); productCategoryService.removeByCategoryProductIds(product1categorypk[0], product1pk); getTxReadOnly().execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(final TransactionStatus transactionStatus) { final List<ProductCategory> pc = productCategoryDAO.findByCriteria( " where e.product.productId = ?1", product1pk); assertEquals(0, pc.size()); transactionStatus.setRollbackOnly(); } }); }