Why does hibernate executes an INSERT followed by UPDATE in below code?
entityManager.getTransaction().begin();
Employee e=new Employee();
e.setId(12);
e.setName("employee_12");
e.setAge(26);
entityManager.persist(e);
e.setName("employee_12_modified");
entityManager.getTransaction().commit();
Output:-
Hibernate:
insert
into
Employee
(age, name, id)
values
(?, ?, ?)
Hibernate:
update
Employee
set
age=?,
name=?
where
id=?
Why doesnt’ hibernate just send an INSERT query with the new value of employee name when context is flushed? Why the need of update?