Bonjour,
J'aimerai avoir votre avis sur le mapping des tables de ma base de donnée sous hibernate.
Mon model de base de donnée
Le choix d'implémentation
Le mapping (en User.java)
Mapping ClientUser.java
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 @Entity @Inheritance(strategy = InheritanceType.JOINED) @Table(name = "user", catalog = "portailweb", uniqueConstraints = @UniqueConstraint(columnNames = "login")) public class User implements java.io.Serializable { /** * */ private static final long serialVersionUID = 1L; protected int idUser; protected String login; protected String password; public User() { } public User(int idUser, String login, String password) { this.idUser = idUser; this.login = login; this.password = password; } public User(int idUser, String login, String password, ClientUser clientUser) { this.idUser = idUser; this.login = login; this.password = password; this.clientUser = clientUser; } @Id @Column(name = "id_user", unique = true, nullable = false) public int getIdUser() { return this.idUser; } public void setIdUser(int idUser) { this.idUser = idUser; } @Column(name = "login", unique = true, nullable = false, length = 20) public String getLogin() { return this.login; } public void setLogin(String login) { this.login = login; } @Column(name = "password", nullable = false, length = 20) public String getPassword() { return this.password; } public void setPassword(String password) { this.password = password; } }
Mapping Client.java
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 = "client_user", catalog = "portailweb") public class ClientUser extends User implements java.io.Serializable { /** * */ private static final long serialVersionUID = 1L; private Client client; public ClientUser() { } public ClientUser(Client client) { this.client = client; } @OneToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL) @JoinColumn(name = "id_client", nullable = false) public Client getClient() { return this.client; } public void setClient(Client client) { this.client = client; } }
En fait je rencontre un petit bug au niveau de mon application et je voudrai savoir si c'est mon mapping qui est en cause ou autre chose.
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 @Entity @Table(name = "client", catalog = "portailweb") public class Client implements java.io.Serializable { /** * */ private static final long serialVersionUID = 1L; private int idClient; private String nom; private ClientUser clientUser; public Client() { } public Client(int idClient, String nom) { this.idClient = idClient; this.nom = nom; } public Client(int idClient, String nom, ClientUser clientUser) { this.idClient = idClient; this.nom = nom; this.clientUser = clientUser; } @Id @Column(name = "id_client", unique = true, nullable = false) public int getIdClient() { return this.idClient; } public void setIdClient(int idClient) { this.idClient = idClient; } @Column(name = "nom", nullable = false) public String getNom() { return this.nom; } public void setNom(String nom) { this.nom = nom; } @OneToOne(fetch = FetchType.LAZY, mappedBy = "client") public ClientUser getClientUser() { return this.clientUser; } public void setClientUser(ClientUser clientUser) { this.clientUser = clientUser; } }
Merci de votre temps
Partager