@Test
public void testCreate2recipesWithSameIngredients() throws Exception {
// recette1
Ingredient pain = new Ingredient();
pain.setLabel("pain");
RecipeIngredient _100gPain = new RecipeIngredient(pain, "100g");
recipe.addRecipeIngredient(_100gPain);
Assert.assertNull(recipe.getId());
recipeDAO.save(recipe);
flushSession();
// recette2
Recipe recipe2 = new Recipe();
recipe2.setTitle("title2");
Iterator<RecipeIngredient> it = recipe.getRecipeIngredients()
.iterator();
// les ingredients détachés
Ingredient i1 = new Ingredient();
i1.setId(it.next().getIngredient().getId());
RecipeIngredient ri1 = new RecipeIngredient(i1, "200g");
recipe2.addRecipeIngredient(ri1);
Ingredient i2 = new Ingredient();
i2.setId(it.next().getIngredient().getId());
RecipeIngredient ri2 = new RecipeIngredient(i2, "300g");
recipe2.addRecipeIngredient(ri2);
assertFalse(i1.getId().equals(i2.getId()));
assertFalse(i1.equals(i2));
recipeDAO.save(recipe2);
assertEquals(2, recipe2.getRecipeIngredients().size());
flushSession();