Salut,
j'ai une interface d'ajout produit qui contient list déroulante libelle de catégorie, lorsque je fait l'insertion des donnée le clé étrangère enregistre dans la base NULL
un produit appartient à un catégorie
un catégorie peut contient plusieurs produit

Classe Produit:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "FK_CODE_CATEGORIE")
private Categorie categorie;
 
public Produit(String designation, int tva, double ht, int quantite, String unite, int stockMin) {
this.designation = designation;
this.tva = tva;
this.ht = ht;
this.quantite = quantite;
this.unite = unite;
this.stockMin = stockMin;
}
Classe Catégorie:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
 
  @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "CODE_CATEGORIE")
    private int codeCategorie;
    @Column(name = "LIBELLE")
    private String libelle;
 
@OneToMany(targetEntity = Produit.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "categorie")
private List<Produit> produits;
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
    @Override
    public void ajouterProduit(Produit p) {
        Session session = HibernateUtil.getSessionFactory().openSession();
        try {
            session.beginTransaction();
            session.save(p);
            session.getTransaction().commit();
            session.close();
            System.out.print("bien ajouté");
        } catch (HibernateException e) {
            System.out.print("erreur insertion" + e.getMessage());
        }
    }
Quelqu'un saurait-il m'indiquer comment résoudre ce problème ?

Merci d'avance pour votre aide.