【发布时间】:2017-03-29 17:05:27
【问题描述】:
我正在尝试使用主键更新我的数据库行。但遇到此异常
异常
HTTP Status 500 – Internal Server Error
Type Exception Report
Message Request processing failed; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:981)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:871)
javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:845)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
控制器
@RequestMapping(value="edit/product/success" ,method=RequestMethod.POST)
public ModelAndView editProduct(@ModelAttribute ("prdt") Product p)
{
ModelAndView model=new ModelAndView("pl");
model.addObject("Update","Updated Successfully");
pd.update(p);
return model;
}
道实现
public void update( Product p) {
Session session=sessionFactory.openSession();
session.update(p);
session.flush();
session.close();
}
jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ include file="header.jsp"%>
<%@ page isELIgnored="false"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<%@ page isELIgnored="false" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$( function() {
$( "#mfg" ).datepicker();
} );
</script>
</head>
<body>
<br>
<h2 align="center">PRODUCT FORM</h2><hr>
<div class="col-md-2 "></div>
<div align="center"><div class="container"><div class="col-md-8 ">
<form:form method="POST" action="${pageContext.request.contextPath}/edit/product/success" commandName="prdt" enctype="multipart/form-data" >
<table class="table table-hover">
<tr>
<td> <form:label path="product_Name"> Enter Product Name</form:label></td>
<td><form:input type="text" path="product_Name" class="form-control" value="${d.product_Name }"/></td>
</tr>
<tr>
<td> <form:label path="descripction"> Enter Product Descripction</form:label></td>
<td><form:input type="text" path="descripction" class="form-control" value="${d.descripction }"/></td>
</tr>
<tr>
<td> <form:label path="price"> Enter Product Price</form:label></td>
<td><form:input type="text" path="price" class="form-control" value="${d.price }" />
</td></tr>
<tr>
<td> <form:label path="mfg_Date"> Enter Manufacture Date</form:label></td>
<td><form:input type="text" id="mfg" path="mfg_Date" class="form-control" value ="${d.mfg_Date}"/></td>
</tr>
<tr>
<td> <label> Choose Image</label></td>
<td><form:input type="file" path="image" class="form-control" /></td>
</tr>
</table>
<input type="submit" class="btn btn-primary btn-block" value="Save Changes" class="form-control"/>
</form:form>
</div></div></div></body>
</html>
请检查并告诉我我的错误..我已经查看了它。但没有发现任何异常。
注意:
数据检索工作正常。仅在更新中遇到问题
【问题讨论】:
标签: spring hibernate maven spring-mvc