通过将它们映射到二进制数据来读取和写入blob [英] read and write blobs by mapping them to binary data

查看:131
本文介绍了通过将它们映射到二进制数据来读取和写入blob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



实体


$ b $我得到以下异常:尝试从使用hibernate JPA的Sybase DB读取blob。 b

  @Lob 
@Column(length = 100000)
private byte [] fileContent;

public byte [] getFileContent(){
return fileContent;
}

public void setFileContent(byte [] fileContent){
this.fileContent = fileContent;
}



ioc.Registry方法com.sybase.jdbc3.jdbc.SybResultSet.getBlob (字符串)不受支持,不应被调用。
ioc.Registry操作跟踪:
ioc.Registry [1]在Purchase_Request
触发事件'activate'TapestryModule.RequestExceptionHandler处理未请求的异常请求失败:方法com.sybase.jdbc3。 jdbc.SybResultSet.getBlob(String)不被支持,不应该被调用。
org.apache.tapestry5.ioc.internal.OperationException:方法com.sybase.jdbc3.jdbc.SybResultSet.getBlob(String)不受支持,不应该被调用。



我遇到以下hibernate线程,它提供了一个链接,指向如何通过将blob映射到二进制数据来读取和写入blob的示例,但链接已死亡。

主题
https://forum.hibernate.org/viewtopic.php?f=1&t=936553



Dead Link
< a href =http://www.hibernate.org/73.html =nofollow> http://www.hibernate.org/73.html



我想知道是否有人可以提供一个例子或文章描述如何做到这一点?



更新



我发现以下JIRA问题概述了此问题
https:// issue.jboss.org/browse/JBPAPP-2867



Laura声称:此问题的解决方法是创建映射到该用户定义的类型的



是否有人熟悉创建一个用户定义的类型?

解决方案

您可以尝试在映射中使用java.sql.Blob而不是字节数组。你可以使用Hibernate.createBlob()函数来从字节数组,字符串,输入流中转换一个blob。这样做的好处是延迟加载(只有在休眠会话打开之前)。

否则,在内存中加载较大的对象会消耗很多堆空间。

p>

  private void setBlob(Blob blob)
{
this.image = toByteArray(blob);
}

私人Blob getBlob()
{
return Hibernate.createBlob(this.image);
}


I'm getting the following exception trying to read a blob from a Sybase DB using hibernate JPA.

Entity

@Lob
@Column(length=100000)    
private byte[] fileContent;

public byte[] getFileContent() {
    return fileContent;
}

public void setFileContent(byte[] fileContent) {
    this.fileContent = fileContent;
}

ioc.Registry The method com.sybase.jdbc3.jdbc.SybResultSet.getBlob(String) is not supported and should not be called. ioc.Registry Operations trace: ioc.Registry [ 1] Triggering event 'activate' on Purchase_Request TapestryModule.RequestExceptionHandler Processing of request failed with uncaught exception: The method com.sybase.jdbc3.jdbc.SybResultSet.getBlob(String) is not supported and should not be called. org.apache.tapestry5.ioc.internal.OperationException: The method com.sybase.jdbc3.jdbc.SybResultSet.getBlob(String) is not supported and should not be called.

I come across the following hibernate thread which provided a link to an example of how to read and write blobs by mapping them to binary data, however the link is dead.

Thread https://forum.hibernate.org/viewtopic.php?f=1&t=936553

Dead Link http://www.hibernate.org/73.html

I'm wondering if anybody could provide an example or an article describing how to do this?

UPDATE

I found the following JIRA issue outlining this problem https://issues.jboss.org/browse/JBPAPP-2867

Laura claims the "The workaround for this issue is to create user-defined types that map to the Sybase text and image types."

Is anybody familiar with creating a user defined type?

解决方案

You can try using java.sql.Blob instead of byte array in your mapping. You can use Hibernate.createBlob() function to convert a blob from byte array, String, input stream. The advantage of this is lazy loading ( Only till the hibernate session is open).

Otherwise..in memory loading of larger object can consume lot of heap space.

 private void setBlob(Blob blob) 
 {
    this.image = toByteArray(blob);
 }

 private Blob getBlob()
 {
   return Hibernate.createBlob(this.image);
 }

这篇关于通过将它们映射到二进制数据来读取和写入blob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆