我想弄清楚使用hibernate在數據庫中實現大文件(〜600 MB)存儲庫的對象設計。 請建議正確的方法/設計?Java大文件被保存在數據庫中 - 對象設計
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
}
});
將這樣一個大文件存儲在數據庫中的原因是什麼? –
將文件保存在磁盤上並在數據庫中存儲路徑不是一個好的解決方案嗎? –
不幸的是,它需要將大型zip文件存儲在數據庫中。 – nkare