I am working under a project that is update the data's in MySQL table using Hibernate. Whenever I run the project, the exception is shown as below.
[Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1]
Controller
@RequestMapping(value = "/disableEmployeeMaster", method = RequestMethod.POST)
public @ResponseBody void disableEmployee(HttpServletRequest request)
{
EmployeeMaster employeeMaster = new EmployeeMaster();
try
{
String employeeId = request.getParameter("employeeId");
employeeMaster.setIsDel("Y");
mainService.disableEmployee(employeeId , employeeMaster);
}
catch(Exception e)
{
logger.error(e.getMessage());
}
}
Service Implementation
@Override
public void disableEmployee(String Id, EmployeeMaster employeeMaster) {
Session session = null;
Transaction transaction = null;
try
{
session = sessionFactory.openSession();
transaction = session.beginTransaction();
session.update(Id, employeeMaster);
transaction.commit();
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
finally
{
session.close();
}
}
You have't set employeeId to EmployeeMaster class object. to update any entity needs it's primary key. You can refer following code :
employeeMaster.setEmployeeId(employeeId);
Controller
@RequestMapping(value = "/disableEmployeeMaster", method = RequestMethod.POST) public @ResponseBody void disableEmployee(HttpServletRequest request) { EmployeeMaster employeeMaster = new EmployeeMaster(); try { String employeeId = request.getParameter("employeeId"); employeeMaster.setEmployeeId(employeeId); employeeMaster.setIsDel("Y"); mainService.disableEmployee(employeeId , employeeMaster); } catch(Exception e) { logger.error(e.getMessage()); } }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.