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
springMvc Hibernate CRUD应用程序无法删除_Spring_Hibernate_Spring Mvc_Crud - Fatal编程技术网

springMvc Hibernate CRUD应用程序无法删除

springMvc Hibernate CRUD应用程序无法删除,spring,hibernate,spring-mvc,crud,Spring,Hibernate,Spring Mvc,Crud,我无法成功删除记录或数据。 我想我的问题出在ProductController.java内部。 帮我摆脱这个错误 list.jsp 错误在事务bean中。。。。。。 因此,我设置了会话管理和事务管理代码,设置了无法从数据库中删除的注释字段。您是否可以确定问题的确切性质,并仅粘贴相关代码。您是如何配置事务管理的? <%@page session="false" %> <%@page contentType="text/html;charset=UTF-8" %> <

我无法成功删除记录或数据。 我想我的问题出在ProductController.java内部。 帮我摆脱这个错误


list.jsp
错误在事务bean中。。。。。。
因此,我设置了会话管理和事务管理

代码,设置了无法从数据库中删除的注释字段。

您是否可以确定问题的确切性质,并仅粘贴相关代码。您是如何配置事务管理的?
<%@page session="false" %>
<%@page contentType="text/html;charset=UTF-8" %>
<%@page pageEncoding="UTF-8" %>

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>:PharmaCloud System::</title>
    <c:import url="../css.jsp"/>
</head>
<body>
<div class="container">
    <h1>Products List</h1>

    <div class="span-28 last">
        <fieldset>
            <c:forEach items="${Product}" var="products">
                <p>Code : ${products.productid}</p>

                <p>ISBN : ${products.productname}</p>

                <p>Title : ${products.producttype}</p>


                <ul>
                    <li>
                        <form:form action="../${products.productid}" method="GET">
                        <input alt="Detail" type="image" value="Detail"/>
                        </form:form>
                    <li><form:form action="../${products.productid}" method="DELETE">
                        <input alt="Delete" title="Delete Person" type="image"
                               value="Delete"/>
                    </form:form></li>
                </ul>
            </c:forEach>
            <c:if test="${pageCount>1}">
                <c:forEach begin="1" end="${pageCount}" var="page" step="1">
                    <a href="<c:url value="../list/${page}"/>">${page}</a>

                </c:forEach>
            </c:if>
        </fieldset>
        <ul>
            <li><a href="<c:url value="/"/>">Main Menu</a></li>
            <li><a href="<c:url value="/products"/>">Create Product</a></li>
        </ul>
    </div>
</div>
</body>
</html>
package com.os.springjpa.controller;

import javax.validation.Valid;
import java.lang.*;
import org.apache.log4j.Logger;
import org.hibernate.type.LongType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.os.springjpa.dao.BookDao;
import com.os.springjpa.entity.Book;
import com.os.springjpa.utils.Utils;

/**
 * @author kris;
 *         This class is using Path Variable style as example like Rest
 *         Style. Path Variable will handling like url string but so simple then
 *         url string. I'm also still not found how to make url string as simple
 *         as posible in view layer.
 */
@Controller
@RequestMapping("/book")
public class BookController {

    @Autowired
    private BookDao bookDao;
    private final int PAGE_SIZE = 2;
    Logger logger = Logger.getLogger(BookController.class);

    @RequestMapping(method = RequestMethod.GET)
    public String form(Model model) {
    System.out.println(org.hibernate.Version.getVersionString());
        model.addAttribute(new Book());
        return "book/create";
    }

    @RequestMapping(method = RequestMethod.POST)
    public String create(@Valid Book book, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            logger.info("Error has been detect");
            return "book/create";
        }
        if (bookDao.saveOrUpdate(book)) {
            book = bookDao.getByIsbn(book.getIsbn());
            return "redirect:/book/" + book.getId();
        } else {
            return "/exception";
        }
    }

    @RequestMapping(method = RequestMethod.PUT)
    public String update(@Valid Book book, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            logger.info("Error has been detect");
            return "book/update";
        }
        if (bookDao.saveOrUpdate(book)) {
            return "redirect:/book/" + book.getId();
        } else {
            return "/exception";
        }
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
    public String delete(@PathVariable("id") Integer id) {
        logger.info("Delete Method Has Call");
        Book book = bookDao.getById(id);
        if (bookDao.delete(book)) {
            return "redirect:/book/list/1";
        } else {
            return "/exception";
        }
    }

    @RequestMapping(value = "/{id}", method = RequestMethod.GET)
    public String detail(@PathVariable Integer id, Model model) {
        Book book = bookDao.getById(id);
        if (book == null) {
            return "/exception";
        }
        model.addAttribute(book);
        return "book/detail";
    }

    @RequestMapping(value = "/edit/{id}", method = RequestMethod.GET)
    public String edit(@PathVariable Integer id, Model model) {
        Book book = bookDao.getById(id);
        if (book == null) {
            return "/exception";
        }
        model.addAttribute(book);
        return "book/update";
    }

    @RequestMapping(value = "/list/{page}", method = RequestMethod.GET)
    public String listPaging(@PathVariable Integer page, Model model) {
        // Create simple pagination
        model.addAttribute("books", bookDao.getAll((page - 1) * PAGE_SIZE, PAGE_SIZE));
      //model.addAttribute("pageCount", Utils.getPageCount(PAGE_SIZE, (Long) bookDao.countAllBook().get(0)));
        model.addAttribute("pageCount", Utils.getPageCount(PAGE_SIZE, Long.parseLong(bookDao.countAllBook().get(0).toString())));
        return "book/list";
    }

}