I have two classes Ingredient and Allergen, and I want to persist it.
Ingredient has a One to many relationship with Allergen
public class Ingredient() {
@OneToMany
List<Allergen> allergens;
}
The problem is that every time I save a new object of Ingredient, then creates one Allergen in Allergen table pera each that appears in the Ingredient allergen list. For example if an ingredient has a inside the list "gluten", and another ingredient has the same allergen then the table Allergens contains a duplication of same allergen, how can avoid this behavior ?. I have tried assigning the same Allergen id but not works.