Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring HTTP状态500–;内部服务器错误_Spring_Hibernate_Maven_Spring Mvc - Fatal编程技术网

Spring HTTP状态500–;内部服务器错误

Spring HTTP状态500–;内部服务器错误,spring,hibernate,maven,spring-mvc,Spring,Hibernate,Maven,Spring Mvc,我正在尝试使用主键更新我的数据库行。但遇到此异常 例外情况 控制器 Dao Impl Jsp 在此处插入标题 $(函数(){ $(“#制造商”).datepicker(); } ); 产品形式 输入产品名称 输入产品描述 输入产品价格 输入制造日期 选择图像 请检查一下,让我知道我的错误1.我已经查过了,但没有发现任何不正常的地方 注: 数据检索工作正常。仅更新时遇到问题请检查您试图保存到数据库中的产品实体。Hibernate尝试查找ID为(主键值)的实体,如果该实体中的pk值已更改,并且

我正在尝试使用主键更新我的数据库行。但遇到此异常

例外情况 控制器 Dao Impl Jsp

在此处插入标题
$(函数(){
$(“#制造商”).datepicker();
} );

产品形式
输入产品名称 输入产品描述 输入产品价格 输入制造日期 选择图像
请检查一下,让我知道我的错误1.我已经查过了,但没有发现任何不正常的地方

注:
数据检索工作正常。仅更新时遇到问题

请检查您试图保存到数据库中的产品实体。Hibernate尝试查找ID为(主键值)的实体,如果该实体中的pk值已更改,并且对该实体调用了更新,则会发生上述错误


检查实体是否具有相同的id,或者id是否被替换,或者是否在某处设置为null。在您的情况下,id可能为空。

尝试使用以下方法:

Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.update(p);
session.flush();
session.close();
tx.commit();
当hibernate找不到需要更新的所有行时,通常会导致此错误。这意味着,当您尝试更新从数据库中提取的某些对象时,它们实际上已经不存在(或者根本不存在)


这可能是因为另一个线程正在删除它们,或者DB的隔离模式设置为read_Uncommitted,因此由另一个事务创建的行无法保存(由于事务失败),不再存在。

但我已在hibernate配置中定义了事务。仍然面对相同的问题,您可以共享所有文件!对于update()和saveOrUpdate()方法,id生成器值应该在数据库中。帮助我
@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();
}
<%@ 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>
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.update(p);
session.flush();
session.close();
tx.commit();