org hibernate id IdentifierGenerationException
Bonjour,
Voici mes entités:
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 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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
| package entities;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
@Entity
public class Agence implements Serializable {
@EmbeddedId
private AgencePK pk;
@ManyToOne
@JoinColumn(name = "COD_POST", nullable = true)
private CodePostal codePostal;
@ManyToOne
@JoinColumn(name = "COD_PAYS", nullable = true)
private Pays codePays;
@ManyToOne
@JoinColumn(name = "COD_LOCA", nullable = true)
private Localite localite;
@Column(name="LIB_AGEN")
private String libAgen;
@Column(name="ADR_AGEN")
private String adrAgen;
@Column(name="VIL_AGEN")
private String vilAgen;
@Column(name="TEL_AGEN")
private String telAgen;
@Column(name="FAX_AGEN")
private String faxAgen;
@Column(name="EMAIL_AGEN")
private String emailAgen;
@Column(name="PER_CONT_AGEN")
private String perContAgen;
@Column(name="RES_AGEN")
private String resAgen;
public Agence() {
super();
}
public AgencePK getPk() {
return this.pk;
}
public void setPk(AgencePK pk) {
this.pk = pk;
}
public String getLibAgen() {
return this.libAgen;
}
public void setLibAgen(String libAgen) {
this.libAgen = libAgen;
}
public String getAdrAgen() {
return this.adrAgen;
}
public void setAdrAgen(String adrAgen) {
this.adrAgen = adrAgen;
}
public String getVilAgen() {
return this.vilAgen;
}
public void setVilAgen(String vilAgen) {
this.vilAgen = vilAgen;
}
public String getTelAgen() {
return this.telAgen;
}
public void setTelAgen(String telAgen) {
this.telAgen = telAgen;
}
public String getFaxAgen() {
return this.faxAgen;
}
public void setFaxAgen(String faxAgen) {
this.faxAgen = faxAgen;
}
public String getEmailAgen() {
return this.emailAgen;
}
public void setEmailAgen(String emailAgen) {
this.emailAgen = emailAgen;
}
public String getPerContAgen() {
return this.perContAgen;
}
public void setPerContAgen(String perContAgen) {
this.perContAgen = perContAgen;
}
public String getResAgen() {
return this.resAgen;
}
public void setResAgen(String resAgen) {
this.resAgen = resAgen;
}
public CodePostal getCodePostal() {
return codePostal;
}
public void setCodePostal(CodePostal codePostal) {
this.codePostal = codePostal;
}
public Pays getCodePays() {
return codePays;
}
public void setCodePays(Pays codePays) {
this.codePays = codePays;
}
public Localite getLocalite() {
return localite;
}
public void setLocalite(Localite localite) {
this.localite = localite;
}
} |
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
|
package entities;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Embeddable;
import javax.persistence.JoinColumn;
@Embeddable
public class AgencePK implements Serializable {
@Column(name="COD_AGEN")
private String codAgen;
@Column(name="COD_BANQ")
private String codBanq;
private static final long serialVersionUID = 1L;
public AgencePK() {
super();
}
public String getCodAgen() {
return this.codAgen;
}
public void setCodAgen(String codAgen) {
this.codAgen = codAgen;
}
public String getCodBanq() {
return codBanq;
}
public void setCodBanq(String codBanq) {
this.codBanq = codBanq;
}
@Override
public boolean equals(Object o) {
if (o == this) {
return true;
}
if ( ! (o instanceof AgencePK)) {
return false;
}
AgencePK other = (AgencePK) o;
return this.codAgen.equals(other.codAgen)
&& this.codBanq.equals(other.codBanq);
}
@Override
public int hashCode() {
final int prime = 31;
int hash = 17;
hash = hash * prime + this.codAgen.hashCode();
hash = hash * prime + this.codBanq.hashCode();
return hash;
}
} |
Mon problème est que lorsque j'essaye d'insérer une nouvelle agence, ça génère l'exception: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save().
Merci