JPA ManyToMany ajouter un champ
Bonjour.
J'ai deux modèles (Paiement et Echeance) liés par une relation ManyToMany, c'est à dire qu'un paiement peut concerner zéro ou plusieurs échéances et une échéance peut être concernée par zéro ou plusieurs paiements.
Code java
Code:
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
| package com.sil.gpc.domains;
import java.sql.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.PrimaryKeyJoinColumn;
@Entity(name = "Paiement")
public class Paiement{
@Id
@Column(name = "numPaiement", length = 20)
@PrimaryKeyJoinColumn(name = "numPaiement" )
private String numPaiement;
private Date datePaiement;
@Column(length = 50)
private String contribuable;
private boolean validePaiement;
@Column(length = 150)
private String Observation;
private Date dateSaisie;
//Liaison avec la table Echeance
@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.MERGE, targetEntity = Echeance.class)
@JoinTable(name = "PaiementEcheance", joinColumns = {@JoinColumn(name="numPaiement")},
inverseJoinColumns = {@JoinColumn(name="idEcheance")})
private List<Echeance> echeancesPaiement;
public Paiement() {
super();
// TODO Auto-generated constructor stub
}
public String getNumPaiement() {
return numPaiement;
}
public void setNumPaiement(String numPaiement) {
this.numPaiement= numPaiement;
}
public Date getDatePaiement() {
return datePaiement;
}
public void setDatePaiement(Date datePaiement) {
this.datePaiement= datePaiement;
}
public String getContribuable() {
return contribuable;
}
public void setContribuable(String contribuable) {
this.contribuable = contribuable;
}
public boolean isValidePaiement() {
return validePaiement;
}
public void setValidePaiement(boolean validePaiement) {
this.validePaiement= validePaiement;
}
public String getObservation() {
return Observation;
}
public void setObservation(String observation) {
Observation = observation;
}
public Date getDateSaisie() {
return dateSaisie;
}
public void setDateSaisie(Date dateSaisie) {
this.dateSaisie = dateSaisie;
}
} |
code java
Code:
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
|
package com.sil.gpc.domains;
import java.io.Serializable;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
@SuppressWarnings("serial")
@Entity
public class Echeance implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long idEcheance;
private String mois;
private Date dateEcheance;
//Liaison avec la table paiement
@ManyToMany(targetEntity = OpCaisse.class,fetch = FetchType.EAGER,cascade = CascadeType.REFRESH)
@JoinTable(name = "PaiementEcheance",
joinColumns = {@JoinColumn(name="idEcheance")},
inverseJoinColumns = {@JoinColumn(name="numPaiement")})
private List<Paiement> paiementsEcheance ;
public Echeance() {
super();
// TODO Auto-generated constructor stub
}
public Echeance(String mois, Date dateEcheance, Contrat contrat) {
super();
this.mois = mois;
this.dateEcheance = dateEcheance;
this.payeEcheance = payeEcheance;
this.contrat = contrat;
}
public Long getIdEcheance() {
return idEcheance;
}
public void setIdEcheance(Long idEcheance) {
this.idEcheance = idEcheance;
}
public String getMois() {
return mois;
}
public void setMois(String mois) {
this.mois = mois;
}
public Date getDateEcheance() {
return dateEcheance;
}
public void setDateEcheance(Date dateEcheance) {
this.dateEcheance = dateEcheance;
}
} |
Actuellement, lorsque j'exécute mon projet, les tables Paiement et Echeance sont créées avec la table association PaiementEcheance.
Mon problème est que je veux ajouter un champ Montant de type double dans la table PaiementEcheance. Comment dois-je procéder, s'il vous plait?