Bonjour à tous,
Je ne suis pas sur d'être sur le bon forum car ma requête touche à la fois hibernate dans l'absolu mais que j'applique en utilisant jpa ... bref
Je n'arrive pas à choisir la bonne solution pour venir me brancher sur un modèle de base existant. J'ai un début de mapping mais je ne sais pas si je vais dans le bon sens.
Mon modèle est le suivant :
Je dispose de 3 tables :
- Une table contact : informations sur une personne
- Table mail : différents mail d'une personne
- Table typemail : Définie le type de mail (perso, pro ...) : l'id de cette table est par exemple : P pour perso. C'est donc une liste des types dispo
une table d'association est liée à ces 3 tables, la clé primaire de cette table est l'agrégation des 3 clés primaires des autres table (contact, mail, typemail).
J'ai donc (je simplifie le contenu) :
contact : id_contact
mail : id_mail
mailtype : id_type
table d'asso : contact_mail : id_contact + id_mail + id_type
Un enregistrement de la table d'asso peut donc avoir cette forme :
id_contact : 100001
id_mail : 123456
id_type : P
Pour le moment mon mapping est le suivant :
Contact :
Mail :
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 @Entity @Table(schema = "COMMON", name = "COM_CONTACT") @NamedQueries( { @NamedQuery(name="Contact.findById", query="select c from Contact c where c.id = :id") } ) public class Contact { @Id //@GeneratedValue(generator="triggerAssigned") //@GenericGenerator(name="triggerAssigned", // strategy = "com.edhec.usrmgt.orm.hibernate.util.TriggerAssignedIdentityGenerator" // ) //@Column(name = "ID",length = 20, unique=false, nullable=false) protected String id; @Column(name = "NAME",length = 250, unique=false, nullable=false) protected String name; @Column(name = "INTERNAL_REFERENCE",length = 50, unique=false, nullable=true) protected String internalReference; @Column(name = "LOGIN",length = 250, unique=true, nullable=true) protected String login; @Column(name = "PASSWORD",length = 250, unique=false, nullable=true) protected String password; @Column(name = "WEB_CODE",length = 250, unique=true, nullable=true) protected String webCode; @Column(name = "DATE_CREATED", length = 30, unique=false, nullable=true) protected String dateCreated; @Column(name = "DATE_MODIFIED", length = 30, unique=false, nullable=true) protected String dateModified; @ManyToMany( fetch=FetchType.EAGER, targetEntity=ComMail.class, cascade={CascadeType.PERSIST, CascadeType.MERGE} ) @JoinTable( name="COM_CONTACT_MAIL", joinColumns=@JoinColumn(name="CNT_ID"), inverseJoinColumns=@JoinColumn(name="MAL_ID") ) protected Collection<ComMail> mail; public Contact() { } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getInternalReference() { return internalReference; } public void setInternalReference(String internalReference) { this.internalReference = internalReference; } public String getLogin() { return login; } public void setLogin(String login) { this.login = login; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getWebCode() { return webCode; } public void setWebCode(String webCode) { this.webCode = webCode; } public String getDateCreated() { return dateCreated; } public void setDateCreated(String dateCreated) { this.dateCreated = dateCreated; } public String getDateModified() { return dateModified; } public void setDateModified(String dateModified) { this.dateModified = dateModified; } public Collection<ComMail> getMail() { return mail; } public void setMail(Collection<ComMail> mail) { this.mail = mail; } }
TypeMail :
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 @Entity @Table(schema = "COMMON", name = "COM_MAIL") @NamedQuery(name="ComMail.findById", query="select c from ComMail c where c.id = :id") public class ComMail { @Id @GeneratedValue(strategy = GenerationType.AUTO) protected String id; @Column(name = "MAIL",length = 250, unique=true, nullable=true) protected String mail; @Column(name = "URL",length = 250, unique=false, nullable=true) protected String url; @Column(name = "DATE_CREATED",length = 250, unique=true, nullable=true) protected String dateCreated; @Column(name = "DATE_MODIFIED",length = 250, unique=true, nullable=true) protected String dateModified; @ManyToMany(mappedBy = "mail") @JoinColumn(name="MAL_ID") protected Collection<Contact> contact; @OneToOne( fetch=FetchType.EAGER, targetEntity=ComAdressKind.class, cascade={CascadeType.PERSIST, CascadeType.MERGE} ) @JoinTable( name="COM_CONTACT_MAIL", joinColumns=@JoinColumn(name="MAL_ID"), inverseJoinColumns=@JoinColumn(name="AKD_ID") ) protected ComAdressKind adressKind; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getMail() { return mail; } public void setMail(String mail) { this.mail = mail; } public String getUrl() { return url; } public void setUrl(String url) { this.url = url; } public String getDateCreated() { return dateCreated; } public void setDateCreated(String dateCreated) { this.dateCreated = dateCreated; } public String getDateModified() { return dateModified; } public void setDateModified(String dateModified) { this.dateModified = dateModified; } @ManyToMany(mappedBy = "mail") @JoinColumn(name="MAL_ID") public Collection<Contact> getContact() { return contact; } public void setContact(Collection<Contact> contact) { this.contact = contact; } public ComAdressKind getAdressKind() { return adressKind; } public void setAdressKind(ComAdressKind adressKind) { this.adressKind = adressKind; } }
J'ai donc mon contact qui dispose d'une liste de mail. Chaque mail est lié à un type.
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 @Entity @Table(schema = "COMMON", name = "COM_ADRESS_KIND") @NamedQuery(name="ComAdressKind.findById", query="select c from ComAdressKind c where c.id = :id") public class ComAdressKind { @Id @GeneratedValue(strategy = GenerationType.AUTO) protected String id; @Column(name = "DATE_CREATED",length = 30, unique=false, nullable=true) protected String dateCreated; @Column(name = "DATE_MODIFIED",length = 30, unique=false, nullable=true) protected String dateModified; @OneToOne(mappedBy = "adressKind") protected ComMail mail; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getDateCreated() { return dateCreated; } public void setDateCreated(String dateCreated) { this.dateCreated = dateCreated; } public String getDateModified() { return dateModified; } public void setDateModified(String dateModified) { this.dateModified = dateModified; } public ComMail getMail() { return mail; } public void setMail(ComMail mail) { this.mail = mail; } }
Dans cette configuration, le système n'arrive pas à récupérer le type de mail.
L'association contact / mail fonctionne correctement.
J'avais également pensé créer un objet pour ma table d'asso pour éventuellement simplifié mais je trouve que ce n'est pas très bien.
J'espère avoir été assez explicite (et pas trop chiant).
Quelqu'un aurait une idée pour résoudre cette problèmatique ?
Merci
Partager