title: Hibernate query timeout exception - I can't save data to the database
body: <p>I would like to save an article, but i got an exception. I don't know what do I do wrong.
  I have three entities: User.class, Category.class and Article.class.</p>
  
  <p>User has these atributes:</p>
  
  <ul>
  <li>id</li>
  <li>name</li>
  <li>email</li>
  <li>password</li>
  <li>List of articles (One-To-Many)</li>
  </ul>
  
  <p>Category has these atributes:</p>
  
  <ul>
  <li>id</li>
  <li>name</li>
  <li>List of categories (Many-To-Many)</li>
  </ul>
  
  <p>Article has these attributes:</p>
  
  <ul>
  <li>id</li>
  <li>title</li>
  <li>content</li>
  <li>publishDate</li>
  <li>User (Many-To-One)</li>
  <li>List of categories (Many-To-Many)</li>
  </ul>
  
  <p>There are my controller and JSP file.</p>
  
  <p><strong>ArticleController.class</strong></p>
  
  <pre><code>@Controller
  public class ArticleController {
  @Autowired
  ArticleService articleService;
  @Autowired
  CategoryService categoryService;
  @Autowired
  UserService userService;
  
  @ModelAttribute("article")
  public Article construct(){
      return new Article();
  }
  
  @RequestMapping("/admin/clanky")
  public String articles(Model model){
      model.addAttribute("articles", articleService.findAll());
      model.addAttribute("categories", categoryService.findAll());
      model.addAttribute("users", userService.findAll());
      return "articles";
  }
  
  @RequestMapping(value="/admin/clanky", method=RequestMethod.POST)
  public String saveArticle(@ModelAttribute("article") Article article, BindingResult result){
      Date publishDate = new Date();
      article.setPublishDate(publishDate);
      articleService.save(article);
      return "redirect:/admin/clanky.html?success=true";
  }
  
  @InitBinder
  public void initBinder(WebDataBinder webDataBinder) {
      SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm");
      dateFormat.setLenient(false);
      webDataBinder.registerCustomEditor(Date.class, "publishDate",
              new CustomDateEditor(dateFormat, false));
  }
  
  @InitBinder
  protected void initBinder(HttpServletRequest request,
          ServletRequestDataBinder binder) throws Exception {
      binder.registerCustomEditor(Integer.class, new CustomNumberEditor(
              Integer.class, true));
  }}
  </code></pre>
  
  <p><strong>article.jsp</strong></p>
  
  <pre><code>&lt;form:form commandName="article" cssClass="form-horizontal"&gt;
  &lt;div class="form-group"&gt;
      &lt;form:hidden path="id" class="form-control input-sm" /&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
      &lt;label for="title" class="col-sm-2 control-label"&gt;Title:&lt;/label&gt;
      &lt;div class="col-sm-10"&gt;
          &lt;form:input path="title" cssClass="form-control" /&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
      &lt;label for="content" class="col-sm-2 control-label"&gt;Content:&lt;/label&gt;
      &lt;div class="col-sm-10"&gt;
          &lt;form:textarea path="content" cssClass="form-control" rows="10" /&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
      &lt;label for="publishDate" class="col-sm-2 control-label"&gt;Category:&lt;/label&gt;
      &lt;div class="col-sm-10"&gt;
          &lt;form:select path="categories" cssClass="form-control"&gt;
              &lt;c:forEach items="${categories}" var="category"&gt;
                  &lt;form:option class="form-control" value="${category.id}"&gt;${category.name}&lt;/form:option&gt;
              &lt;/c:forEach&gt;
          &lt;/form:select&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
      &lt;label for="user" class="col-sm-2 control-label"&gt;User:&lt;/label&gt;
      &lt;div class="col-sm-10"&gt;
          &lt;form:select path="user.id" cssClass="form-control"&gt;
              &lt;c:forEach items="${users}" var="user"&gt;
                  &lt;form:option class="form-control" value="${user.id}"&gt;${user.name}&lt;/form:option&gt;
              &lt;/c:forEach&gt;
          &lt;/form:select&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class="form-group"&gt;
      &lt;div class="col-sm-2"&gt;
          &lt;input type="submit" value="Uložit" class="btn btn-lg btn-primary"&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>Could anyone help me, please?</p>
  
  <p>There is a stack trace:</p>
  
  <pre><code>HTTP Status 500 - Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/QueryTimeoutException
  
  type Exception report
  
  message Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/QueryTimeoutException
  
  description The server encountered an internal error that prevented it from fulfilling this request.
  
  exception
  
  org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/QueryTimeoutException
      org.springframework.web.servlet.DispatcherServlet.triggerAfterCompletionWithError(DispatcherServlet.java:1284)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:965)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
      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:647)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:232)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
  root cause
  
  java.lang.NoClassDefFoundError: org/hibernate/QueryTimeoutException
      org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:644)
      org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:799)
      org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:669)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726)
      org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:478)
      org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:272)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
      com.sun.proxy.$Proxy21.save(Unknown Source)
      cz.michalsipek.blog.controller.ArticleController.saveArticle(ArticleController.java:55)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.lang.reflect.Method.invoke(Method.java:606)
      org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
      org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)
      org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
      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:647)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:232)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
  root cause
  
  java.lang.ClassNotFoundException: org.hibernate.QueryTimeoutException
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
      org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
      org.springframework.orm.hibernate3.SessionFactoryUtils.convertHibernateAccessException(SessionFactoryUtils.java:644)
      org.springframework.orm.hibernate3.HibernateTransactionManager.convertHibernateAccessException(HibernateTransactionManager.java:799)
      org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:669)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757)
      org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726)
      org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:478)
      org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:272)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
      com.sun.proxy.$Proxy21.save(Unknown Source)
      cz.michalsipek.blog.controller.ArticleController.saveArticle(ArticleController.java:55)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.lang.reflect.Method.invoke(Method.java:606)
      org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:175)
      org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)
      org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
      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:647)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:232)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
  </code></pre>