@Override @Transactional(propagation = Propagation.MANDATORY) public void deleteIngredientFromAllDishes(Ingredient ingredient) { List<Dish> result = new ArrayList<>(); for (Dish dish : findAll()) { for (Ingredient i : dish.getIngredients()) { if (ingredient.equals(i)) { result.add(dish); } } } for (Dish dish : result) { deleteIngredient(ingredient, dish); } }
private void deleteIngredient(Ingredient ingredient, Dish dish) { dish.getIngredients().remove(ingredient); sessionFactory.getCurrentSession().saveOrUpdate(dish); }