I am trying to make an update on database using Hibernate. When i call merge, it results a new row in database. I don't receive any error. The cod is working, but i want update not insert.
Model:
@Entity
@Table(name = "Books")
public class Manual implements Serializable {
@Id
@GeneratedValue
private int idManual;
private String denumire;
private String disciplina;
private Date dataPostare;
@Enumerated(EnumType.STRING)
private TipManual tipManual;
private String emailContact;
private String telefonContact;
private double pret;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "username")
private User userName;
public Manual() {
}
public Manual(int idManual, String denumire, String disciplina, Date dataPostare, TipManual tipManual,
String emailContact, String telefonContact, double pret, User userName) {
super();
this.idManual = idManual;
this.denumire = denumire;
this.disciplina = disciplina;
this.dataPostare = dataPostare;
this.tipManual = tipManual;
this.emailContact = emailContact;
this.telefonContact = telefonContact;
this.pret = pret;
this.userName=userName;
}
public int getIdManual() {
return idManual;
}
public void setIdManual(int idManual) {
this.idManual = idManual;
}
public String getDenumire() {
return denumire;
}
public void setDenumire(String denumire) {
this.denumire = denumire;
}
This is my model class, i also tried to remove @GeneratedValue for my id, but the problem is the same.
My function for merge:
@Override
@Transactional
public Manual updateBook(Manual book) {
em.merge(book);
em.flush();
return book;
}