如何解决编译Spring3 Hibernate 4时的Hibernate.createBlob()方法错误

如何解决编译Spring3 Hibernate 4时的Hibernate.createBlob()方法错误,spring,hibernate,Spring,Hibernate,在eclipse中编译DocumentManager应用程序时出现问题。它没有获取Hibernate.createBlob(file.getInputStream())方法并给出“类型Hibernate的createBlob(InputStream)方法未定义”。我在Maven中使用Spring3和Hibernate4。请给我建议一些解决办法。下面的代码。。。谢谢 package com.ecom.data.access.controller; import java.io.IOExc

在eclipse中编译DocumentManager应用程序时出现问题。它没有获取Hibernate.createBlob(file.getInputStream())方法并给出“类型Hibernate的createBlob(InputStream)方法未定义”。我在Maven中使用Spring3和Hibernate4。请给我建议一些解决办法。下面的代码。。。谢谢

package com.ecom.data.access.controller;

    import java.io.IOException;
    import java.io.OutputStream;
    import java.sql.Blob;
    import java.sql.SQLException;
    import java.util.Map;

    import javax.servlet.http.HttpServletResponse;

    import com.ecom.data.access.dao.DocumentDAO;
    import com.ecom.data.access.model.Document;

    import org.apache.commons.io.IOUtils;
    import org.hibernate.Hibernate;
    import org.springframework.beans.factory.annotation.Autowired;
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.ModelAttribute;
    import org.springframework.web.bind.annotation.PathVariable;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.multipart.MultipartFile;

    @Controller
    public class DocumentController {

        @Autowired
        private DocumentDAO documentDao;

        @RequestMapping("/index")
        public String index(Map<String, Object> map) {
            try {
                map.put("document", new Document());
                map.put("documentList", documentDao.list());
            }catch(Exception e) {
                e.printStackTrace();
            }

            return "documents";
        }

        @RequestMapping(value = "/save", method = RequestMethod.POST)
        public String save(
                @ModelAttribute("document") Document document,
                @RequestParam("file") MultipartFile file) {


            System.out.println("Name:" + document.getName());
            System.out.println("Desc:" + document.getDescription());
            System.out.println("File:" + file.getName());
            System.out.println("ContentType:" + file.getContentType());

            try {
                Blob blob = Hibernate.createBlob(file.getInputStream());

                document.setFilename(file.getOriginalFilename());
                document.setContent(blob);
                document.setContentType(file.getContentType());
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                documentDao.save(document);
            } catch(Exception e) {
                e.printStackTrace();
            }

            return "redirect:/index.html";
        }

        @RequestMapping("/download/{documentId}")
        public String download(@PathVariable("documentId")
                Integer documentId, HttpServletResponse response) {

            Document doc = documentDao.get(documentId);
            try {
                response.setHeader("Content-Disposition", "inline;filename=\"" +doc.getFilename()+ "\"");
                OutputStream out = response.getOutputStream();
                response.setContentType(doc.getContentType());
                IOUtils.copy(doc.getContent().getBinaryStream(), out);
                out.flush();
                out.close();

            } catch (IOException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            }


            return null;
        }

        @RequestMapping("/remove/{documentId}")
        public String remove(@PathVariable("documentId")
                Integer documentId) {

            documentDao.remove(documentId);

            return "redirect:/index.html";
        }
    }
package com.ecom.data.access.controller;
导入java.io.IOException;
导入java.io.OutputStream;
导入java.sql.Blob;
导入java.sql.SQLException;
导入java.util.Map;
导入javax.servlet.http.HttpServletResponse;
导入com.ecom.data.access.dao.DocumentDAO;
导入com.ecom.data.access.model.Document;
导入org.apache.commons.io.IOUtils;
导入org.hibernate.hibernate;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.stereotype.Controller;
导入org.springframework.web.bind.annotation.ModelAttribute;
导入org.springframework.web.bind.annotation.PathVariable;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RequestMethod;
导入org.springframework.web.bind.annotation.RequestParam;
导入org.springframework.web.multipart.MultipartFile;
@控制器
公共类文档控制器{
@自动连线
私有文档dao DocumentDAO;
@请求映射(“/index”)
公共字符串索引(映射){
试一试{
map.put(“document”,newdocument());
map.put(“documentList”,documentDao.list());
}捕获(例外e){
e、 printStackTrace();
}
归还“文件”;
}
@RequestMapping(value=“/save”,method=RequestMethod.POST)
公共字符串保存(
@ModelAttribute(“文档”)文档,
@RequestParam(“文件”)多部分文件{
System.out.println(“Name:+document.getName());
System.out.println(“Desc:+document.getDescription());
System.out.println(“文件:“+File.getName());
System.out.println(“ContentType:+file.getContentType());
试一试{
Blob Blob=Hibernate.createBlob(file.getInputStream());
document.setFilename(file.getOriginalFilename());
文件设置内容(blob);
document.setContentType(file.getContentType());
}捕获(IOE异常){
e、 printStackTrace();
}
试一试{
documentDao.save(文档);
}捕获(例外e){
e、 printStackTrace();
}
返回“重定向:/index.html”;
}
@请求映射(“/download/{documentId}”)
公共字符串下载(@PathVariable(“documentId”)
整数documentId,HttpServletResponse){
Document doc=documentDao.get(documentId);
试一试{
response.setHeader(“内容处置”、“内联;文件名=\”“+doc.getFilename()+”\”);
OutputStream out=response.getOutputStream();
response.setContentType(doc.getContentType());
复制(doc.getContent().getBinaryStream(),out);
out.flush();
out.close();
}捕获(IOE异常){
e、 printStackTrace();
}捕获(SQLE异常){
e、 printStackTrace();
}
返回null;
}
@请求映射(“/remove/{documentId}”)
公共字符串删除(@PathVariable(“documentId”)
整数(documentId){
documentDao.remove(documentId);
返回“重定向:/index.html”;
}
}

我认为您无法解决该方法,因为它不存在

在Hibernate3中,有一个与您调用的方法几乎相同的方法,但它有一个额外的整数参数来指定大小


该方法仍然存在于Hibernate4中,但位于不同的位置。您可能需要调用该方法,然后在该方法上使用该方法。

我认为您无法解析该方法,因为它不存在

在Hibernate3中,有一个与您调用的方法几乎相同的方法,但它有一个额外的整数参数来指定大小


该方法仍然存在于Hibernate4中,但位于不同的位置。您可能希望调用该方法,然后在该方法上使用该方法。

如果Hibernate.createBlob()方法被折旧,您可以使用Hibernate.getLobCreator(sessionfactory.getCurrentSession()).createBlob()方法,而不是Hibernate.createBlob()方法被折旧,您可以使用Hibernate.getLobCreator(sessionfactory.getCurrentSession()).createBlob()相反

这是正确的,没有
Hibernate.createBlob
方法。你认为为什么会有这样一个方法?它存在于Hibernate 3中,尽管没有那样的签名。没错,没有
Hibernate.createBlob
方法。你认为为什么会有这样一个方法?它存在于Hibernate3中,尽管没有那个签名。