Bonjour,
Je développe une application (JSF + EJB3) en partant d'une base de données avec des clés composées. Je rencontre un problème sur la suppression d'enregistrement.
Voici ma classe Entité.
Voici ma classe pour la clé composée
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 @Entity @Table(name="P_COMMUNE") public class PCommune implements Serializable { private PCommunePK pk; private String p_ci_lib; private String p_ci_cp; public String getP_ci_lib() { return p_ci_lib; } public void setP_ci_lib(String p_ci_lib) { this.p_ci_lib = p_ci_lib; } public String getP_ci_cp() { return p_ci_cp; } public void setP_ci_cp(String p_ci_cp) { this.p_ci_cp = p_ci_cp; } @EmbeddedId public PCommunePK getPk() { return pk; } public void setPk(PCommunePK pk) { this.pk = pk; }
Les opérations suivantes fonctionnent correctement : persist, merge, find.
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
39
40
41 @Embeddable public class PCommunePK implements Serializable { @Column(name="P_CI_DEP") private String p_ci_dep; @Column(name="P_CI_COM") private String p_ci_com; public String getP_ci_dep() { return p_ci_dep; } public void setP_ci_dep(String p_ci_dep) { this.p_ci_dep = p_ci_dep; } public String getP_ci_com() { return p_ci_com; } public void setP_ci_com(String p_ci_com) { this.p_ci_com = p_ci_com; } public int hashCode() { int hash = 0; hash += (this.p_ci_dep != null ? this.p_ci_dep.hashCode() : 0); hash += (this.p_ci_com != null ? this.p_ci_com.hashCode() : 0); return hash; } public boolean equals(Object obj) { if (obj == this) return true; if (!(obj instanceof RVoiePK)) return false; if (obj == null) return false; PCommunePK pk = (PCommunePK) obj; return pk.p_ci_com.equals(p_ci_com) && pk.p_ci_dep.equals(p_ci_dep); }
Par contre pour le delete, j'ai l'erreur suivante :
J'ai fait le test de charger une commune, d'afficher son attribut p_ci_lib, de faire un update, et enfin un delete. Mais même erreur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2java.lang.IllegalArgumentException: Removing a detached instance fr.dsit.entite.PCommune#fr.dsit.entite.PCommunePK@dc71
Dites-moi, que le delete fonctionne correctement avec une clé composé, et que j'ai fait une erreur![]()
Partager