I am trying to update an entity, but when I call EntityManager.merge(), it is updating all the columns of the table. But my requirement is to update only those column which are modified. I searched on the Internet and stack overflow and the solution I got is to use @SelectBeforeUpdate and @DynamicUpdate. I tried with these annotation, but its not working. When I tried to update some specific column, all other columns are also updated.
Entity
@Entity
@SelectBeforeUpdate(value=true)
@DynamicUpdate(value=true)
@DynamicInsert(value=true)
@Table(name="Employee")
public class Employee implements Serializable{
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="id")
private int ID;
@Column(name="_first_name")
private String firstName;
@Column(name="_last_name")
private String lastName;
@Column(name="_contact")
private Long contact;
@Column(name="_email")
private String email;
@Column(name="_date_birth")
private Date dob;
@Column(name="_joining_date")
private Date doj;
@Column(name="_salary")
private Integer Salary;
}
DAO
logger.debug("Update method dao :");
logger.debug(manager.getTransaction());
Employee emp = form.getEmployee();
logger.debug(emp);
manager.find(Employee.class,emp.getID());
manager.merge(emp);
In debugging it is updating all the columns