-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: Sybase and blobs
PostPosted: Thu Nov 25, 2004 1:25 am 
Newbie

Joined: Tue Sep 14, 2004 11:33 pm
Posts: 6
Hello

I have googled and configured for a little while now, but cannot load a blob from Sybase. Can anyone give me some pointers? See stack trace below.

Thank you
Jem


Hibernate version:
v2.1.6
Mapping documents:
Code:
<hibernate-mapping>

    <class
        name="**obfuscated**"
        schema="**obfuscated**"
        table="**obfuscated**"
        >

...

        <property name="toffRec1" column="toff_rec1" type="blob" length="255" not-null="true"/>
        <property name="toffRec2" column="toff_rec2" type="blob" length="255" not-null="true"/>
        <property name="toffRec3" column="toff_rec3" type="blob" length="255" not-null="true"/>
        <property name="toffRec4" column="toff_rec4" type="blob" length="255" not-null="true"/>

    </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
session.createCriteria(getDatatype()).add(Expression.eq("autoRef", new Long(key))).uniqueResult();


Full stack trace of any exception that occurs:
Code:
junit.framework.AssertionFailedError: Exception in constructor: testLoadAndSave (java.lang.UnsupportedOperationException: The method com.sybase.jdbc2.jdbc.SybResultSet.getBlob(String) is not supported and should not be called.
   at com.sybase.jdbc2.jdbc.ErrorMessage.raiseRuntimeException(ErrorMessage.java:763)
   at com.sybase.jdbc2.utils.Debug.notSupported(Debug.java:366)
   at com.sybase.jdbc2.jdbc.SybResultSet.getBlob(SybResultSet.java:1362)
   at net.sf.hibernate.type.BlobType.get(BlobType.java:32)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
   at net.sf.hibernate.type.AbstractType.hydrate(AbstractType.java:66)
   at net.sf.hibernate.loader.Loader.hydrate(Loader.java:686)
   at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:627)
   at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:586)
   at net.sf.hibernate.loader.Loader.getRow(Loader.java:501)
   at net.sf.hibernate.loader.Loader.getRowFromResultSet(Loader.java:213)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:281)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
   at net.sf.hibernate.loader.Loader.doList(Loader.java:1033)
   at net.sf.hibernate.loader.Loader.list(Loader.java:1024)
   at net.sf.hibernate.loader.CriteriaLoader.list(CriteriaLoader.java:118)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:3613)
   at net.sf.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:238)
   at net.sf.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:385)
   at com.obfuscated.TestGwmlToFsdDatabase.load(TestGwmlToFsdDatabase.java:27)
   at com.obfuscated.GwmlToFsdDatabaseTest.<init>(GwmlToFsdDatabaseTest.java:27)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
   at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
   at junit.framework.TestSuite.createTest(TestSuite.java:131)
   at junit.framework.TestSuite.addTestMethod(TestSuite.java:114)
   at junit.framework.TestSuite.<init>(TestSuite.java:75)
   at com.intellij.rt.execution.junit.TestRunnerUtil.getTestImpl(TestRunnerUtil.java:117)
   at com.intellij.rt.execution.junit.TextTestRunner2.getTest(TextTestRunner2.java:36)
   at junit.textui.TestRunner.start(TestRunner.java:171)
   at com.intellij.rt.execution.junit.TextTestRunner2.startRunnerWithArgs(TextTestRunner2.java:23)
   at com.intellij.rt.execution.junit2.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:97)
   at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:324)
   at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
)


Name and version of the database you are using:
Sybase SQL Server
Adaptive Server Enterprise/12.0.0.8/P/EBF 11874 ESD2/Sun_svr4/OS 5.7/2058/64bit/FBO/Thu May 20 09:12:03 2004

The generated SQL (show_sql=true):
Code:
select this.auto_ref as auto_ref0_, ... , this.toff_rec4 as toff_rec40_ from obfuscated.dbo.obfuscated this where this.auto_ref=?


Top
 Profile  
 
 Post subject: Sybase and blobs
PostPosted: Thu Nov 25, 2004 10:55 am 
Newbie

Joined: Tue Nov 23, 2004 12:24 pm
Posts: 7
Location: Washington, DC
Sybase JDBC drivers do no support blobs. So you'll have to read blobs as binary data.

You can do that by implementing UserType for binary blobs. There's an example of that in the design patterns area http://www.hibernate.org/73.html.
Read the data as binary instead of blob.

Code:
public Object nullSafeGet(ResultSet rs, String[] names, Object owner)
  throws HibernateException, SQLException
  {
    byte[] data  = rs.getBinary(names[0]);
    return data;
  }


Your mapping file should poin to this new type
Code:
<property name="toffRec1" column="toff_rec1" type="MyBinaryBlob" length="255" not-null="true"/>


Another issue to keep in mind is to use jConnect6.0 sybase drivers with com.sybase.jdbc3.jdbc.SybDriver

jConnect5.5 and older drivers can read only upto 255 bytes of binary data. If your blob has more than 255 bytes, use jConnect6.0 jdbc driver.

If your implementation does not work, let me know, I can post my implementation of the user blob.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2004 7:07 pm 
Newbie

Joined: Tue Sep 14, 2004 11:33 pm
Posts: 6
Thanks very much Vikram. I'll shall try this right away!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 25, 2004 8:01 pm 
Newbie

Joined: Tue Sep 14, 2004 11:33 pm
Posts: 6
It works very well. Thanks!

I needed to implement nullSafeSet as well as the get. Your example made it very clear.

Cheers


Top
 Profile  
 
 Post subject: sybase blob jconnect6
PostPosted: Wed Jun 29, 2005 3:44 am 
Newbie

Joined: Tue Jun 28, 2005 3:17 pm
Posts: 2
I tried to get a Blob from Sybase using hibernate and jconnect 6.0 instead of jconnect5.5. It does not fix the problem because the method getBlob(String) is still unsupported.

Does anybody have a user type blob implementation, Sybase compliant (all the posted implementations are for Oracle) or any other solution to get this field?

Thanks by advance.

See stack trace below :
java.lang.UnsupportedOperationException: La méthode com.sybase.jdbc3.jdbc.SybResultSet.getBlob(String) n'est pas supportée et n'aurait pas dû être appelée.
at com.sybase.jdbc3.jdbc.ErrorMessage.raiseRuntimeException(ErrorMessage.java:953)
at com.sybase.jdbc3.utils.Debug.notSupported(Debug.java:366)
at com.sybase.jdbc3.jdbc.SybResultSet.getBlob(SybResultSet.java:1470)
at org.apache.commons.dbcp.DelegatingResultSet.getBlob(DelegatingResultSet.java:526)
at org.hibernate.type.BlobType.get(BlobType.java:56)
at org.hibernate.type.BlobType.nullSafeGet(BlobType.java:110)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:80)
at org.hibernate.persister.entity.BasicEntityPersister.hydrate(BasicEntityPersister.java:1703)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:918)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:874)
at org.hibernate.loader.Loader.getRow(Loader.java:787)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:293)
at org.hibernate.loader.Loader.doQuery(Loader.java:387)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:206)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1271)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:141)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:126)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2496)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:387)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:368)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:166)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:140)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:201)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:123)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:561)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:556)
at com.bnppam.fms.filestorage.dao.hibernate.StorageFileHibernateDao.retrieveStorageFileById(StorageFileHibernateDao.java:391)
at com.bnppam.fms.filestorage.dao.hibernate.StorageFileHibernateDaoTest.testRetrieveFiles(StorageFileHibernateDaoTest.java:134)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)

Hibernate maping :
java.lang.UnsupportedOperationException: La méthode com.sybase.jdbc3.jdbc.SybResultSet.getBlob(String) n'est pas supportée et n'aurait pas dû être appelée.
at com.sybase.jdbc3.jdbc.ErrorMessage.raiseRuntimeException(ErrorMessage.java:953)
at com.sybase.jdbc3.utils.Debug.notSupported(Debug.java:366)
at com.sybase.jdbc3.jdbc.SybResultSet.getBlob(SybResultSet.java:1470)
at org.apache.commons.dbcp.DelegatingResultSet.getBlob(DelegatingResultSet.java:526)
at org.hibernate.type.BlobType.get(BlobType.java:56)
at org.hibernate.type.BlobType.nullSafeGet(BlobType.java:110)
at org.hibernate.type.AbstractType.hydrate(AbstractType.java:80)
at org.hibernate.persister.entity.BasicEntityPersister.hydrate(BasicEntityPersister.java:1703)
at org.hibernate.loader.Loader.loadFromResultSet(Loader.java:918)
at org.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:874)
at org.hibernate.loader.Loader.getRow(Loader.java:787)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:293)
at org.hibernate.loader.Loader.doQuery(Loader.java:387)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:206)
at org.hibernate.loader.Loader.loadEntity(Loader.java:1271)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:141)
at org.hibernate.loader.entity.EntityLoader.load(EntityLoader.java:126)
at org.hibernate.persister.entity.BasicEntityPersister.load(BasicEntityPersister.java:2496)
at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:387)
at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:368)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:166)
at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:140)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:201)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:123)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:561)
at org.hibernate.impl.SessionImpl.get(SessionImpl.java:556)
at com.bnppam.fms.filestorage.dao.hibernate.StorageFileHibernateDao.retrieveStorageFileById(StorageFileHibernateDao.java:391)
at com.bnppam.fms.filestorage.dao.hibernate.StorageFileHibernateDaoTest.testRetrieveFiles(StorageFileHibernateDaoTest.java:134)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)

Sql trace :
select completest0_.filstoIvc_id as filstoIvc1_1_, completest0_.filsto_vc_filname as filsto2_1_1_, completest0_.filsto_vc_desc as filsto3_1_1_, completest0_.filsto_bi_nevdel as filsto4_1_1_, completest0_.filsto_vc_rqster as filsto5_1_1_, completest0_.filsto_dt_datetime as filsto6_1_1_, completest0_.filsto_im_file as filsto7_1_1_, completest0_.filsto_in_appliid as filsto8_1_1_, completest0_.filsto_vc_type as filsto9_1_1_, filetype1_.filtypIvc_winext as filtypIvc1_0_, filetype1_.filtyp_vc_type as filtyp2_0_0_, filetype1_.filtyp_vc_desc as filtyp3_0_0_ from devcom_file_storage completest0_ inner join devcom_file_types filetype1_ on completest0_.filsto_vc_type=filetype1_.filtypIvc_winext where completest0_.filstoIvc_id=?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2005 3:46 am 
Newbie

Joined: Tue Jun 28, 2005 3:17 pm
Posts: 2
I am sorry :

Hibernate mapping :

<hibernate-mapping package="com.bnppam.fms.filestorage.model">
<class name="CompleteStorageFile" table="devcom_file_storage" mutable="false" lazy="false">

<id name="id" column="filstoIvc_id" type="string">
<generator class="uuid.hex"/>
</id>

<property name="fileName" column="filsto_vc_filname" type="string" not-null="true"/>
<property name="description" column="filsto_vc_desc" type="string"/>
<property name="neverDelete" column="filsto_bi_nevdel" type="boolean" not-null="true"/>
<property name="uid" column="filsto_vc_rqster" type="string" not-null="true"/>
<property name="datetime" column="filsto_dt_datetime" type="timestamp" not-null="true"/>
<property name="fileBlob" column="filsto_im_file" type="blob" not-null="true"/>
<property name="applicationId" column="filsto_in_appliid" type="long" not-null="true"/>

<many-to-one name="fileType" class="FileType" column="filsto_vc_type" not-null="true" cascade="save-update"/>

</class>

</hibernate-mapping>

Thanks for your help!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 29, 2005 11:38 am 
Newbie

Joined: Tue Nov 23, 2004 12:24 pm
Posts: 7
Location: Washington, DC
Sybase JDBC drivers do not support blobs. So, the work around is to read and write the blobs by mapping them to binary data.

An example on how this can be acheived is given in http://www.hibernate.org/73.html


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.