Java大文件保存在数据库中-对象设计
我正在尝试找出对象设计来使用 hibernate 在数据库中实现大文件(~600 MB)存储库。 请提出正确的方法/设计?
class ModelClass{
String name; //meta data
...
Option 1.
byte[] file; // dont want to load the content of the entire file
// in memory by using this but hibernate recognizes
// this datatype
Option 2.
InputStream inputStream;
OutputStream outputStream;
// I can have the methods to provide the input or output stream
// but i dont think its a clean approach. I am not sure how
// I will be able to work with hibernate with streams
Option 3.
File fileHandle;
}
还有其他选择吗?
我想调用 hibernateTemplate 的 save(Object) 方法将对象保存在数据库中。不知道我是否应该只在类中包含元数据并单独处理文件保存和检索。
提前致谢。
另一个可行的解决方案是使用“工作”界面。目的是避免将文件内容加载到内存中。
session.doWork(new Work(){
@Override
public void execute(Connection conn) {
//direct sql queries go here
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我编写了一个 SerializedFile 类,将数据保存在文件中。当读取对象时,它会创建一个临时文件。
这里是:
I have written a SerializableFile class that keeps data in a file. When the object is read, it creates a temporary file.
Here it is:
Open JPA 支持使用 一些数据库使用 @Persistent 注释:
Open JPA supports a @Persistent annotation with some databases:
即使您仍然使用 RDBMS 作为数据存储,您也应该考虑将此二进制数据存储到文件系统中,并将路径的目录/位置保存到数据库中,而不是将其存储为将
BLOB
或CLOB
存入数据库。Even if you are still using an
RDBMS
as a data store, you should consider storing this binary data into a file system, and saving the directory / location of the path into the database, instead of storing this as aBLOB
orCLOB
into the database.