我曾经成功的插入过大于4k的数据。下面是我做的一个完整的程序:
public void createFile(Long folder_id, InputStream content) throws Exception {
Session session = sessions.openSession();
Transaction tx = null;
Content_file file = new Content_file();
file.setContent(Hibernate.createBlob(new byte[1]));
Content_folder folder = (Content_folder) session.load(Content_folder.class,
folder_id);
file.setFolder_id(folder_id);
try {
tx = session.beginTransaction();
session.save(file);
session.flush();
session.refresh(file, LockMode.UPGRADE);
oracle.sql.BLOB blobs = (oracle.sql.BLOB) file.getContent();
OutputStream os = blobs.getBinaryOutputStream();
int chunk = blobs.getChunkSize();
byte[] buffer = new byte[chunk];
int bytesread = 0;
while ( (bytesread = content.read(buffer, 0, chunk)) != -1) {
os.write(buffer, 0, bytesread);
}
os.flush();
os.close();
tx.commit();
}
catch (HibernateException he) {
if (tx != null)
tx.rollback();
throw he;
}