Bonjour tout le monde.
Je travaille sur la persistance des entités avec JPA, j'ai trois classes Need, Specification et Rationale.
entre Need et Specification une relation manyToMany, entre Need et Rationale une realtion manyToMany,en plus j'ai besoins d'une information supplémentaire sur chaque relation, alors il faut modéliser chaque relation entre deux classes comme une entité à part et le clé primaire de chacune de ces entités d'associations est est composé des deux clés primaires des classes concernées.
En fait j'ai fait tous ça, mais le problème c'est que si je teste le déploiement des trois classes avec une entité d'association Need_Spacification par exemple ça marche mais si j'ajoute une deuxième entité d'association Rationale_Need par exemple j'obtient une exception " Unable to build EntityManagerFactory " .
je vais essayer de copier les parties nécessaire de mes classes.
1-Classe Need:
----------------------------------------------------------
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 @Entity @Table(name="needs") public class Need implements Serializable{ private static final long serialVersionUID = 1L; private int number; private Date dateOfCreation; private List<RationaleNeed> RN; private List<Rationale>rationales; private List<NeedSpecification> NS; private List<Specification> specifications; @Id @GeneratedValue(strategy=GenerationType.IDENTITY) public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } @OneToMany(mappedBy="need",fetch=FetchType.EAGER,cascade={CascadeType.MERGE,CascadeType.REMOVE}) public List<RationaleNeed> getRN() { return RN; } public void setRN(List<RationaleNeed> rN) { RN = rN; } @ManyToMany @JoinTable(name="RN" , joinColumns={ @JoinColumn(name="need_number") } , inverseJoinColumns={ @JoinColumn(name="rationale_number") } ) public List<Rationale> getRationales() { return rationales; } public void setRationales(List<Rationale> rationales) { this.rationales = rationales; } @OneToMany(mappedBy="need",fetch=FetchType.EAGER,cascade={CascadeType.MERGE,CascadeType.REMOVE}) public List<NeedSpecification> getNS() { return NS; } public void setNS(List<NeedSpecification> nS) { NS = nS; } @ManyToMany(mappedBy="needs",cascade={CascadeType.MERGE,CascadeType.PERSIST}) public List<Specification> getSpecifications() { return specifications; } public void setSpecifications(List<Specification> specifications) { this.specifications = specifications; } }
--------------------------------Classe Specification ----------------------
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
42
43
44 @Entity @Table(name="specifications") public class Specification implements Serializable{ private static final long serialVersionUID = 1L; private int number; private List<NeedSpecification>NS; private List<Need> needs; @Id @GeneratedValue(strategy=GenerationType.IDENTITY) public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } @OneToMany(mappedBy="specification",fetch=FetchType.EAGER,cascade={CascadeType.MERGE,CascadeType.REMOVE}) public List<NeedSpecification> getNS() { return NS; } public void setNS(List<NeedSpecification> nS) { NS = nS; } @ManyToMany @JoinTable( name="NS" , joinColumns={ @JoinColumn(name="specification_number") } , inverseJoinColumns={ @JoinColumn(name="need_number") } ) public List<Need> getNeeds() { return needs; } public void setNeeds(List<Need> needs) { this.needs = needs; } }
-------------------------Classe Rationale ------------------------------
et les entités d'association sont:
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 @Entity @Table(name="rationales") public class Rationale implements Serializable{ private static final long serialVersionUID = 1L; private int number; private List<RationaleNeed> RN; //23/03 private List<Need> needs; @Id @GeneratedValue(strategy=GenerationType.IDENTITY) public int getNumber() { return number; } public void setNumber(int number) { this.number = number; } @OneToMany(mappedBy="rationale",fetch=FetchType.EAGER,cascade={CascadeType.MERGE,CascadeType.REMOVE}) public List<RationaleNeed> getRN() { return RN; } public void setRN(List<RationaleNeed> rN) { RN = rN; } @ManyToMany(mappedBy="rationales",cascade={CascadeType.MERGE,CascadeType.PERSIST}) public List<Need> getNeeds() { return needs; } public void setNeeds(List<Need> needs) { this.needs = needs; } }
-----------------------Classe Need_Specification----------------------
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
42 @Entity @Table(name="NS") public class NeedSpecification implements Serializable { private static final long serialVersionUID = 1L; private NeedSpecificationPK IdDoublon; private boolean state; // c'est l'information supplémentaire private Need need; private Specification specification; @EmbeddedId public NeedSpecificationPK getIdDoublon() { return IdDoublon; } public void setIdDoublon(NeedSpecificationPK idDoublon) { IdDoublon = idDoublon; } public boolean isState() { return state; } public void setState(boolean state) { this.state = state; } @ManyToOne public Need getNeed() { return need; } public void setNeed(Need need) { this.need = need; } @ManyToOne public Specification getSpecification() { return specification; } public void setSpecification(Specification specification) { this.specification = specification; } }
-------------------------Classe Rationale_Need------------------
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 @Entity @Table(name="RN") public class RationaleNeed implements Serializable { private static final long serialVersionUID = 1L; private RationaleNeedPK IdDoublon; private boolean state; private Need need; private Rationale rationale; @EmbeddedId public RationaleNeedPK getIdDoublon() { return IdDoublon; } public void setIdDoublon(RationaleNeedPK idDoublon) { IdDoublon = idDoublon; } public void setRationale(Rationale rationale) { this.rationale = rationale; } public boolean isState() { return state; } public void setState(boolean state) { this.state = state; } @ManyToOne public Need getNeed() { return need; } public void setNeed(Need need) { this.need = need; } @ManyToOne public Rationale getRationale() { return rationale; } }
Les deux classe d'associations Need_Specification et Rationale_Need utilisent des classe Embaddable comme clé primaire:
Pour la classe Need_Specification,Need_SpecificationPK , et RationaleNeedPK pour la classe Rationale_Need.
-------------------------NeedSpecificationPK ---------------------------
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
42
43 @Embeddable public class NeedSpecificationPK implements Serializable{ private static final long serialVersionUID = 1L; private int needNumber; private int specificationNumber; @Column(name="need_id") public int getNeedNumber() { return needNumber; } public void setNeedNumber(int needNumber) { this.needNumber = needNumber; } @Column(name="spacification_id") public int getSpecificationNumber() { return specificationNumber; } public void setSpecificationNumber(int specificationNumber) { this.specificationNumber = specificationNumber; } public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof NeedSpecificationPK)) { return false; } NeedSpecificationPK castOther = (NeedSpecificationPK)other; return (this.needNumber == castOther.needNumber) && (this.specificationNumber == castOther.specificationNumber); } public int hashCode() { final int prime = 31; int hash = 17; hash = hash * prime + this.needNumber; hash = hash * prime + this.specificationNumber; return hash; } }
--------------------RationaleNeedPK -------------------------
-------------------environnement de travail.-------------------------
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
42
43 @Embeddable public class RationaleNeedPK implements Serializable { private static final long serialVersionUID = 1L; private int needNumber; private int rationaleNumber; @Column(name="need_id") public int getNeedNumber() { return needNumber; } public void setNeedNumber(int needNumber) { this.needNumber = needNumber; } @Column(name="rationale_id") public int getRationaleNumber() { return rationaleNumber; } public void setRationaleNumber(int rationaleNumber) { this.rationaleNumber = rationaleNumber; } public boolean equals(Object other) { if (this == other) { return true; } if (!(other instanceof RationaleNeedPK)) { return false; } RationaleNeedPK castOther = (RationaleNeedPK)other; return (this.needNumber == castOther.needNumber) && (this.rationaleNumber == castOther.rationaleNumber); } public int hashCode() { final int prime = 31; int hash = 17; hash = hash * prime + this.needNumber; hash = hash * prime + this.rationaleNumber; return hash; } }
Base de données: Mysql 5.1.31
IDE: eclipse endigo
serveur d'application: jBoss 5.1
je suis bloqué dans cette étape, si vous pouvez m'aider n'hésitez pas de le faire et merci d'avance.
Partager