org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是org.hibernate.exception.LockTimeoutException:

时间:2016-04-28 07:30:20

标签: java spring hibernate jsp

我正在使用Hibernate。我在这个项目中使用了层次结构“Controller,Service,DAO”。我试图在db中保存数据。这些数据将DTO传递给DB。但我使用complaint.jsp页面运行项目和填写表单。我得到以下异常......

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.LockTimeoutException: could not execute statement
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

org.hibernate.exception.LockTimeoutException: could not execute statement
    org.hibernate.dialect.MySQLDialect$1.convert(MySQLDialect.java:447)
    org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
    org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
    org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
    org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:190)
    org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:62)
    org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3124)
    org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3587)
    org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:103)
    org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:453)
    org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:345)
    org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
    org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
    org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1218)
    org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:421)
    org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
    org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177)
    edu.ijse.tcd.dao.impl.ComplaintDAOImpl.addComplaint(ComplaintDAOImpl.java:35)
    edu.ijse.tcd.service.impl.ComplaintServiceImpl.addComplaint(ComplaintServiceImpl.java:30)
    edu.ijse.tcd.controller.ComplaintController.addComplaint(ComplaintController.java:42)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:497)
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1094)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4226)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4158)
    com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2615)
    com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2776)
    com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2840)
    com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2082)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2334)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2262)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2246)
    org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:187)
    org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:62)
    org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3124)
    org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3587)
    org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:103)
    org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:453)
    org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:345)
    org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:350)
    org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:56)
    org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1218)
    org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:421)
    org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.beforeTransactionCommit(JdbcTransaction.java:101)
    org.hibernate.engine.transaction.spi.AbstractTransactionImpl.commit(AbstractTransactionImpl.java:177)
    edu.ijse.tcd.dao.impl.ComplaintDAOImpl.addComplaint(ComplaintDAOImpl.java:35)
    edu.ijse.tcd.service.impl.ComplaintServiceImpl.addComplaint(ComplaintServiceImpl.java:30)
    edu.ijse.tcd.controller.ComplaintController.addComplaint(ComplaintController.java:42)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    java.lang.reflect.Method.invoke(Method.java:497)
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:689)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:938)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:870)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
    org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
抱怨.jsp页面

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
<!--            jobNumber varchar(100),
    complaint_id varchar(10) primary key,
    nature varchar(200),
    instruction varchar(200),-->
<form:form action="addComplaint" modelAttribute="ComplaintMap" method="POST">

         <form:input path="jobNumber" placeholder="jobNumber ?"></form:input>
         <form:input type="hidden" path="complaintId" value="0" placeholder="complaintId ?"></form:input>
         <form:input path="nature" placeholder="nature ?"></form:input>
         <form:input path="instruction" placeholder="instruction ?"></form:input>
         <input value="SAVE" type="submit"/>
</form:form>
        </table>
    </body>
</html>

以下代码是控制器层代码

@Controller
@RequestMapping("/")
public class ComplaintController {

    @Autowired
    private ComplaintService complaintService;

    @RequestMapping(value = "complaint", method = RequestMethod.GET)
    public String loadComplaint(ModelMap map){
        Complaint complaint = new Complaint();
        ArrayList<Complaint> complaints = complaintService.getComplaints();

        map.addAttribute("ComplaintMap", complaint);
        map.addAttribute("ComplaintList", complaints);

        return "complaint";
    }

    @RequestMapping(value = "addComplaint" , method = RequestMethod.POST)
    public String addComplaint(@Valid Complaint complaint,ModelMap map){
        complaintService.addComplaint(complaint);

        ArrayList<Complaint> complaints = complaintService.getComplaints();

        map.addAttribute("ComplaintMap", new Complaint());
        map.addAttribute("ComplaintList", complaints);
        return "complaint";

    }


}

以下代码是DAO图层代码

@Repository
public class ComplaintDAOImpl implements ComplaintDAO{

    @Autowired
    private SessionFactory sessionFactory;

    public Session getSession(){
        return sessionFactory.openSession();
    }

    public boolean addComplaint(Complaint complaint) {
        Session session = getSession();
        session.beginTransaction();
        session.save(complaint);
        session.getTransaction().commit();
        session.close();
        return true;
    }

}
}

Db.sql代码

CREATE TABLE Complaint(
    jobNumber varchar(100),
    complaint_id varchar(10) primary key,
    nature varchar(200),
    instruction varchar(200),
    constraint foreign key(jobNumber) references JobCard(jobNumber) 
    on delete cascade on update cascade  
);

0 个答案:

没有答案