private void reatachIngredients(Recipe recipe) {
for (Iterator<RecipeIngredient> it = recipe.getRecipeIngredients()
.iterator(); it.hasNext();) {
RecipeIngredient ri = it.next();
Ingredient ingredient = ri.getIngredient();
if (ingredient.getId() != null && ingredient.getId() != 0) {
Ingredient reference = getEntityManager().getReference(
Ingredient.class, ingredient.getId());
ri.setIngredient(reference);
} else {
getEntityManager().persist(ingredient);
}