在 Hibernate 中映射 byte[] 并逐块添加文件
我有一个按块接收 100 Mb 视频文件的 Web 服务
public void addFileChunk(Long fileId, byte[] buffer)
如何使用 hibernate 将此文件存储在 Postgresql 数据库中?
使用常规 JDBC 非常简单。我将在我的 Web 服务方法中使用以下代码:
LargeObject largeObject = largeObjectManager.Open(fileId, LargeObjectManager.READWRITE);
int size = largeObject.Size();
largeObject.Seek(size);
largeObject.Write(buffer);
largeObject.Close();
How can I receive the same function using Hibernate?并按块存储该文件?
在我看来,将每个文件块存储在单独的行中作为 bytea 似乎不是一个聪明的主意。皮斯的建议。
I have web service which receives 100 Mb video file by chunks
public void addFileChunk(Long fileId, byte[] buffer)
How can I store this file in Postgresql database using hibernate?
Using regular JDBC is very straight forward. I would use the following code inside my web service method:
LargeObject largeObject = largeObjectManager.Open(fileId, LargeObjectManager.READWRITE);
int size = largeObject.Size();
largeObject.Seek(size);
largeObject.Write(buffer);
largeObject.Close();
How can I achieve the same functionality using Hibernate? and store this file by chunk?
Storing each file chunk in separate row as bytea seems to me not so smart idea. Pease advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现在建议在数据库中存储 100MB 的文件。我会将它们存储在文件系统中,但考虑到事务处于活动状态,使用 Servlet 似乎是合理的。
its now advisable to store 100MB files in database. I would instead store them in the filesystem, but considering transactions are active, employing Servlets seems reasonable.
请参阅 http://in.relation.to/Bloggers/PostgreSQLAndBLOBs
是的,byteas 会很糟糕。 Hibernate 有一种方法可以继续使用大对象,并且您可以保留流接口。
see http://in.relation.to/Bloggers/PostgreSQLAndBLOBs
Yeah byteas would be bad. Hibernate has a way to continue to use large objects and you get to keep the streaming interface.