Bonjour à tous,
J'essaye depuis plusieurs heures de faire une table de relation N:M entre deux Model.
Ma table commande
Ma table produit
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 @Entity public class Commande extends Model { public Date dateCommande; @Required public Date dateRetrait; public double acompte; @MaxSize(11) public String numCheque; public double montant; @Required @OneToOne public Client client; @OneToMany(mappedBy="commande",cascade=CascadeType.ALL) public List<CommandeProduit> listeProduits; @OneToMany(mappedBy="commande", cascade=CascadeType.ALL) public List<CommandeMenu> listeMenus; public Commande() { } public Commande(Date dateCommande, Date dateRetrait, double acompte, String numCheque, Client client) { super(); this.dateCommande = dateCommande; this.dateRetrait = dateRetrait; this.acompte = acompte; this.numCheque = numCheque; this.client = client; } ... }
Ma table CommandeProduit
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 @Entity public class Produit extends Model { @Lob @Required public String designation; @Required public double uvc; public boolean alacarte; @Required public double prix; @OneToOne public Categorie categorie; @OneToOne public Fournisseur fournisseur; public Produit() { } public Produit(String designation, double uvc, boolean alacarte, double prix, Categorie categorie, Fournisseur fournisseur) { this.designation = designation; this.uvc = uvc; this.alacarte = alacarte; this.prix = prix; this.categorie = categorie; this.fournisseur = fournisseur; } @Override public String toString() { return designation; } }
Lorsque j'essaye d'ajouter un objet dans la table CommandeProduit j'ai le droit à une superbe erreur que je n'arrive pas à corriger :'(
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 @Entity public class CommandeProduit extends Model { @ManyToOne @JoinColumn(name="commande_id",unique=false) public Commande commande; @ManyToOne @JoinColumn(name="produit_id") public Produit produit; @Required public int quantity; public CommandeProduit(Commande commande, Produit produit, int quantity) { this.commande = commande; this.produit = produit; this.quantity = quantity; } @Override public String toString() { return "N° " + commande.id + "[" + produit.designation + "]"; } }
Détails
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 Java exception PersistenceException occured : org.hibernate.exception.ConstraintViolationException: could not insert: [models.CommandeProduit]
Si quelqu'un pouvais m'aider à résoudre ce petit soucis.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4 Caused by: java.sql.SQLException: Integrity constraint violation - no parent FKE 19335AFE062650F table: COMMANDE in statement [insert into CommandeProduit (id, c ommande_id, produit_id, quantity) values (null, ?, ?, ?)]
Je vous remercie par avance
Partager