0

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?

Code Junkie
  • 7,602
  • 26
  • 79
  • 141

1 Answers1

0

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);
 }
Ram Reddy
  • 123
  • 6
  • Hi Ram, I'm slightly confused, I tried using blob as the datatype, private Blob content and I get a compiling error, "Basic attributes can only be of the following types: Java primitive types". I'm also not sure what your doing with toByteArray. Could you elaborate a little bit more on your example. Thanks. – Code Junkie Apr 13 '12 at 14:46