Reputation: 303
I have table with one primary key (auto increment) and three columns except that primary key column
S.No EmpId EmpName Month salary
1 1700 xxxx Jan 17000
2 1701 yyyy Jan 70000
3 1700 xxxx Feb 16750
4 1702 yyyy Jan 70000
5 1700 xxxx Mar 17000
6 1700 xxxx April 16000
This table contains details about employee names and his/her monthly salary details, I need to update the salary of employee xxx in Jan Month.
How can i do this in hibernate by using session.saveorupdate method?
Upvotes: 0
Views: 294
Reputation: 2469
Assuming that you are working with persistent "employee" objects, I think something like this should work out.
Transaction t = session.beginTransaction();
employee.setEmpId(id);
employee.setEmpName(name);
employee.setSalary(newSalary);
...
session.saveOrUpdate(employee);
System.out.println("Successfully updated");
t.commit();
Upvotes: 1