*原因:com.mysql.jdbc.MysqlDataTruncation:数据截断:数据太长,第1行的“内容”列
我试图解决这个问题很多天
名称:vivek srivastava
描述:联系人
文件:文件
ContentType:应用程序/ pdf
服务:托管,代管
休眠:插入文档(地址,联系方式,内容,手机号码,名称,名称,服务提供,状态,上载日期)值(?,?,?,?,?,?,?,?,?)
org.hibernate.exception.DataException:无法插入:[com.ams.bean.Document]
package com.ams.bean;
import java.sql.Blob;
import java.sql.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
@Entity
@Table(name="documents")
public class Document {
@Id
@GeneratedValue
@Column(name="id")
private Integer id;
@Column(name="name")
private String name;
@Column(name="poname")
private String poname;
@Column(name="mobileno")
private String mobileno;
@Column(name="contact")
private String contact;
@Column(name="content")
@Lob
private Blob content;
@Column(name="serviceprovided")
private String serviceprovided;
@Column(name="status")
private String status;
@Column(name="uploaddate")
private String uploaddate;
@Column(name="address")
private String address;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMobileno() {
return mobileno;
}
public void setMobileno(String mobileno) {
this.mobileno = mobileno;
}
public String getContact() {
return contact;
}
public void setContact(String contact) {
this.contact = contact;
}
public Blob getContent() {
return content;
}
public void setContent(Blob content) {
this.content = content;
}
public String getServiceprovided() {
return serviceprovided;
}
public void setServiceprovided(String serviceprovided) {
this.serviceprovided = serviceprovided;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public String getUploaddate() {
return uploaddate;
}
public void setUploaddate(String uploaddate) {
this.uploaddate = uploaddate;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPoname() {
return poname;
}
public void setPoname(String poname) {
this.poname = poname;
}enter code here
}
@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.getContact());
System.out.println("File:" + file.getName());
System.out.println("ContentType:" + file.getContentType());
System.out.println("service:"+document.getServiceprovided());
try {
Blob blob = Hibernate.createBlob(file.getInputStream());
document.setServiceprovided(document.getServiceprovided());
document.setContent(blob);
document.setAddress(document.getAddress());
document.setName(document.getName());
document.setPoname(document.getPoname());
document.setMobileno(document.getMobileno());
document.setStatus(document.getStatus());
document.setUploaddate(document.getUploaddate());
document.setContact(document.getContact());
} catch (IOException e) {
e.printStackTrace();
}
try {
VMDao.save(document);
} catch(Exception e) {
e.printStackTrace();
}
return "redirect:/customer_details.do";
}
@Transactional(propagation=Propagation.REQUIRED)
public void save(Document document) {
Session session = sessionFactory.getCurrentSession();
session.save(document);
}
答案 0 :(得分:0)
异常很明显,内容ID的值太大(超过64Kb)。考虑使用另一个,例如MEDIUMBLOB或LONGBLOB:
BLOB类型 对象类型对象可以容纳的值长度 TINYBLOB从0到255字节 BLOB从0到65535字节 MEDIUMBLOB从0到16777215字节 LONGBLOB从0到4294967295字节