我的控制器中的代码
FileInsertion fileInsertion = new FileInsertion();
FileUpload fileUpload = new FileUpload();
fileUpload.setFilename((InputStream) new ByteArrayInputStream(byteArray));
//byteArray is the file converted into a byte[]
fileInsertion.insertFile(fileUpload);
//the following happens in a separate method
trns = session.beginTransaction();
session.save(fileUpload);
session.getTransaction().commit();
休眠映射文件
<hibernate-mapping>
<class name="com.sort.process.FileUpload" table="fileupload">
<meta attribute="class-description">
This class contains the file upload detail.
</meta>
<id name="Id" type="int" column="Id">
<generator class="increment" />
</id>
<property name="filename">
<column name="filename" />
</property>
</class>
</hibernate-mapping>
我的目标是在 BLOB 对象的位置将文件插入到数据库表中。但是我得到了这个
Initial SessionFactory creation failed.org.hibernate.MappingException: Could not determine type for: java.io.InputStream, at table: fileupload, for columns: [org.hibernate.mapping.Column(filename)]
我尝试了上述使用ByteArrayInputStream
而不是InputStream
,但徒劳无功。谁能让我知道我在代码中的错误是什么?
提前致谢