Отображение ассоциации таблицы @ManyToMany с дополнительными столбцами и набором - PullRequest
0 голосов
/ 06 мая 2020

У меня есть связь «многие ко многим» между ингредиентами и рецептом с дополнительными столбцами, поэтому я использовал сопоставление таблицы ассоциаций -> моя проблема в том, что я хочу, чтобы для каждого рецепта добавлялся список ингредиентов, но с этой реализацией я могу добавьте только один ингредиент для одного рецепта, это моя ассоциативная таблица. Любая помощь, пожалуйста!

@Entity
@Data 
@AllArgsConstructor
@NoArgsConstructor
@SuperBuilder

public class Ingredients implements Serializable{

    @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="id_ing")
    private Long id_ing;

    @Column(length=20)
    private String libele_ing;

    @Column(length=10)
    private int calorie_ing;

    @OneToMany(mappedBy="ingredients")
    private List<RecetteIngredient> recetteIngredients = new ArrayList<>();



}

класс: Получение

public abstract class Recette implements Serializable{

    @Id @GeneratedValue(strategy=GenerationType.IDENTITY)
    @Column(name="id_Recette")
    private Long id_Recette;


    @Column(length=20)
    private String libele_recette; 

    @Column(length=10)
    private double prix_recette;

    @OneToMany(mappedBy="recette")
    private List<RecetteIngredient> recetteIngredients = new ArrayList<>();
}

это работает хорошо:

RecetteIngredient recetteIngredient = new RecetteIngredient();

recetteIngredient.setRecette(recette1);

recetteIngredient.setIngredient(ingr1);
...