大家好我有这个问题的合并(jpa),首先我读了关于我的问题的所有答案,但没有主题帮助我找到解决方案。 好吧,我有一个表resultat,我想在我的managedbean(jsf)中合并,但当我这样做时,我得到另一行插入
package com.journaldev.jpa.data;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;
@Entity
@Table(name="Resultat")
public class Resultat {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int resultatID;
@ManyToOne
@JoinColumn(name="personneID")
private Etudiant etudiant;
@ManyToOne
@JoinColumn(name="testID")
private Test test;
@Column
private boolean passer;
@Column
private int resultat;
@Temporal(TemporalType.DATE)
@Column
private Date date_passage;
public int getResultatID() {
return resultatID;
}
public void setResultatID(int resultatID) {
this.resultatID = resultatID;
}
public Etudiant getEtudiant() {
return etudiant;
}
public void setEtudiant(Etudiant etudiant) {
this.etudiant = etudiant;
}
public Test getTest() {
return test;
}
public void setTest(Test test) {
this.test = test;
}
public boolean isPasser() {
return passer;
}
public void setPasser(boolean passer) {
this.passer = passer;
}
public int getResultat() {
return resultat;
}
public void setResultat(int resultat) {
this.resultat = resultat;
}
public Date getDate_passage() {
return date_passage;
}
public void setDate_passage(Date date_passage) {
this.date_passage = date_passage;
}
}
我的服务类是
public Resultat findRes(int id)
{
return this.em.find(Resultat.class,id);
}
@Transactional
public Resultat updateR(Resultat emp) {
// Save Personne
return this.em.merge(emp);
}
这就是我在我的managedbean中使用它的方式
Resultat res = testService.findRes(1);
System.out.println("hahowa"+res.getResultatID());
res.setResultatID(score);
res.setPasser(true);
res= testService.updateR(res);