Mon update fait plutôt un insert+JPA
Bonjour
Je voudrais pouvoir modifier la valeur de la clé de mon entité mais j'ai plutot une insertion.
Voici mon entité
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
| @Entity
@Table(name = "affectation")
public class Affectation implements Serializable{
private static final long serialVersionUID = 1L;
public static final String FindByAgentAndFiche="findByAgentAndFiche";
public static final String findByChef="findByChef";
@EmbeddedId
protected AffectationPK affectationPK;
@JoinColumn(name = "Fiche_id", referencedColumnName = "id", insertable = false, updatable = false)
@ManyToOne(optional = false)
private Fiche fiche;
@JoinColumn(name = "Agent_id", referencedColumnName = "login", insertable = false, updatable = false)
@ManyToOne(optional = false)
private Agent agent;
public Affectation() {
}
public Affectation(AffectationPK affectationPK) {
this.affectationPK = affectationPK;
}
public Affectation(String verid, Long id, boolean chef) {
this.affectationPK = new AffectationPK(verid, id, chef);
}
public AffectationPK getAffectationPK() {
return affectationPK;
}
public void setAffectationPK(AffectationPK affectationPK) {
this.affectationPK = affectationPK;
}
//getter setters
} |
la clé embedded
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| @Embeddable
public class AffectationPK implements DAOEntry {
@Basic(optional = false)
@NotNull
@Column(name = "Agent_id")
private String agentid;
@Basic(optional = false)
@NotNull
@Column(name = "Fiche_id")
private Long ficheid;
@Basic(optional = false)
@NotNull
@Column(name = "chef")
private Boolean chef;
public AffectationPK() {
}
public AffectationPK(String agent, Long ficheid,Boolean ch) {
this.agentid = agent;
this.ficheid = ficheid;
this.chef=ch;
} |
le code de test
Code:
1 2 3 4 5 6 7 8
| @Test
public void testAffectation() {
Affectation af1 = affectationDao.find(new AffectationPK("iv", new Long(22), Boolean.TRUE));
af1.getAffectationPK().setChef(Boolean.FALSE);
affectationDao.update(af1);
} |
cordialement