我尝试使用带有hibernate3的blob将文件保存到MySQL.但我总是有java.lang.UnsupportedOperationException:Blob可能无法通过创建会话来操作org.hibernate.lob.BlobImpl.excep(BlobImpl.java:127)
这里有一些代码.
package com.uni.domain;
public class File extends Identifier {
private byte[] data;
private String contentType;
public byte[] getData() {
return data;
}
public File() {}
public void setData(byte[] photo) {
this.data = photo;
}
public boolean isNew() {
return true;
}
public String getContentType() {
return contentType;
}
public void setContentType(String contentType) {
this.contentType = contentType;
}
}
package com.uni.domain;
import org.hibernate.Hibernate;
import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.sql.*;
import java.util.Arrays;
public class PhotoType …Run Code Online (Sandbox Code Playgroud)