Bonsoir à tous j'espère que vous allez bien.J'ai un petit soucis par rapport au annotation en java en réalité j'ai ce diagramme de classe à partir duquel je dois créer des classes et faire leur persistance en base de donnée :
De ce diagramme voici les classes et les annotations que j'ai eu à écrire. Merci de m'aider à le corriger afin de l'améliorer.
--->Classe Client
--->Classe Facture
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 @Entity @Table(name = "T_Client") public class Client { @Id @GeneratedValue( strategy=GenerationType.IDENTITY ) private int idClient; private String nom; private String prenom; private Date dateNaissance; private String telephone; @OneToMany( targetEntity=Facture.class, mappedBy="client" ) private List<Facture> factures = new ArrayList<>(); public Client() { } public Client( int idClient, String nom, String prenom, Date dateNaissance, String telephone ) { this.setIdClient(idClient); this.setNom(nom); this.setPrenom( prenom ); this.setDateNaissance(dateNaissance); this.setTelephone(telephone); } //Mutateur
--->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 @Entity @Table(name="T_Facture") public class Facture { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private int numFact; private Date dateFact; @ManyToOne @JoinColumn(name="idClient", nullable=false) private Client client; @ManyToMany @JoinTable( name = "T_Produit_Facturer", joinColumns = @JoinColumn( name = "idClient" ), inverseJoinColumns = @JoinColumn( name = "numFact" ) ) private List<Produit> produits = new ArrayList<>(); public Facture() {} public Facture(Date dateFact, Client client) { this.setDateFact( dateFact ); this.setClient( client ); }
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 @Entity @Table(name="T_Facture") public class Facture { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) private int numFact; private Date dateFact; @ManyToOne @JoinColumn(name="idClient", nullable=false) private Client client; @ManyToMany @JoinTable( name = "T_Produit_Facturer", joinColumns = @JoinColumn( name = "idClient" ), inverseJoinColumns = @JoinColumn( name = "numFact" ) ) private List<Produit> produits = new ArrayList<>(); public Facture() {} public Facture(Date dateFact, Client client) { this.setDateFact( dateFact ); this.setClient( client ); }
Partager