-->
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: Fighting the Blobs
PostPosted: Wed Mar 03, 2004 9:09 am 
Newbie

Joined: Wed Mar 03, 2004 8:52 am
Posts: 5
Location: Brussels, Belgium
I'm currently trying a simple insert/retrieve of a row contaning a Blob (long raw). It looks like that:

Code:
    Tt tt2 = new Tt();
    tt2.setCarte((Blob)Hibernate.createBlob(new FileInputStream("e:\\Z.GIF")));
    session.save(tt2);
    session.flush();
    session.connection().commit();
    session.close();
         
    Session session2 = sf.openSession();               
    // Retrieve the record: notice the space padding ...
    Tt tt3 = (Tt)session2.get(Tt.class, "joe                      ", LockMode.UPGRADE);


The insert part, i guess, works allright except i can't tell what's inside the long raw column.
On 'get' (or 'load') i had this exception:
Code:
13:48:07,695  WARN JDBCExceptionReporter:38 - SQL Error: 17004, SQLState: null
13:48:07,695 ERROR JDBCExceptionReporter:46 - Invalid column type
13:48:07,705  WARN JDBCExceptionReporter:38 - SQL Error: 17004, SQLState: null
13:48:07,705 ERROR JDBCExceptionReporter:46 - Invalid column type
13:48:07,705 ERROR JDBCExceptionReporter:38 - could not load: [test.Tt#joe                 ]
java.sql.SQLException: Invalid column type
   at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:114)
   at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:156)
   at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:219)
   at oracle.jdbc.driver.OracleStatement.getBLOBValue(OracleStatement.java:2822)
   at oracle.jdbc.driver.OracleResultSetImpl.getBLOB(OracleResultSetImpl.java:458)
   at oracle.jdbc.driver.OracleResultSetImpl.getBlob(OracleResultSetImpl.java:511)
   at oracle.jdbc.driver.OracleResultSet.getBlob(OracleResultSet.java:1703)
   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:611)
   at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:552)
   at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:511)
   at net.sf.hibernate.loader.Loader.getRow(Loader.java:426)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:209)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
   at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:831)
   at net.sf.hibernate.loader.Loader.loadEntity(Loader.java:851)
   at net.sf.hibernate.loader.SimpleEntityLoader.load(SimpleEntityLoader.java:58)
   at net.sf.hibernate.persister.EntityPersister.load(EntityPersister.java:419)
   at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2081)
   at net.sf.hibernate.impl.SessionImpl.doLoad(SessionImpl.java:2004)
   at net.sf.hibernate.impl.SessionImpl.get(SessionImpl.java:2029)
   at test.Main.main(Main.java:78)


I use Hibernate 2.1.2 on Oracle 8.16
I've tried many things and searched the forum and wiki but this is the best i can get.

Some advice ?

Oh, and by the way, is there a chance taht could work on both Oracle 8i and DB2 7.2 ?

Thanks a lot.
Paulo.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 9:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Blob support is pretty widely varied amongst DB vendors, unfortunately. I personally try to avoid them if at all possible.

You mention that your DDL type is the Oracle RAW or LONG RAW? Not BLOB/CLOB? If that's correct, and you simply want to store string data there, you might want to consider simply serializing your strings into the RAW column. That's completely portable. The drawback is that you'd not be able to "see" what's in that column outside of accessing it through Java to deserialized the string.

As for your error, I'm guessing the Oracle driver is complaining about the type mismatch. It sounds like you have the column defined as RAW and then mapped as BLOB. Those are not complimentary types in JDBC.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 9:57 am 
Newbie

Joined: Wed Mar 03, 2004 8:52 am
Posts: 5
Location: Brussels, Belgium
Unfortunately I have to cope with Blobs :(

As far as i know, there is no BLOB type in native Oracle DDL, whereas it might work better with DB2.
As for the type mismatch, it seemed to work fine for insertion ... How come the BlobType.get (from the exception stack) suddenly finds out the types don't match ...
I've been told the jdbc driver itself might be the problem, workarounds may exist but it ought to be by handling directly jdbc operations (within hibernate).

I'll post here if i can find any solution.

Thanks again.

Paulo.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 11:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Of course Oracle has a BLOB type (are you kidding me, the most pervasive DB vendor out there not having LOB support ?). In the server, Oracle has great support for BLOBS (you can partition BLOB columns off to a seperate tablespace from the rest of the table, etc). What has been lacking, is their JDBC support for BLOBS, at least through 8i. We have not made the switch to 9i yet because of other dependencies, so those versions may be better.

And from what I can tell, you don't have to deal with Blobs. Unless by "have to" you mean you have a pre-existing java domain model which declares things as blobs.

Here is the entry from the Oracle documentation regarding the mapping for the DDL types BLOB and LONGRAW...

SQL Datatypes
JDBC Typecodes
Standard Java Types
Oracle Extension Java Types

RAW
java.sql.Types.BINARY
byte[]
oracle.sql.RAW

RAW
java.sql.Types.VARBINARY
byte[]
oracle.sql.RAW

LONGRAW
java.sql.Types.LONGVARBINARY
byte[]
oracle.sql.RAW

BLOB
java.sql.Types.BLOB
java.sql.Blob
oracle.sql.BLOB

CLOB
java.sql.Types.CLOB
java.sql.Clob
oracle.sql.CLOB


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 11:50 am 
Newbie

Joined: Wed Mar 03, 2004 8:52 am
Posts: 5
Location: Brussels, Belgium
Sorry, my mistake. I've always thought LONG RAW was the equivalent and that no BLOB type existed. Toad just won't give that choice ...
Anyway everything is fine with DB2.
Yet the same code still fails on oracle 8 (socket broken or 0-sized data).

As you said, I must comply with an existing structure using Blobs.
Quick question: how would you store, say, a .PDF document (or any binary) without a Blob ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 03, 2004 12:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
I don't store it into the database...

After the insert, what happens if you query the column through sqlplus? Does it actually show any data?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 04, 2004 9:55 am 
Newbie

Joined: Wed Mar 03, 2004 8:52 am
Posts: 5
Location: Brussels, Belgium
Actually no.

Whereas when the field was a LONG RAW, it put something in it (with the same mapping).

The simplest way to make it work against both DB2 and Oracle is to map those fields as 'binary' and fetch them into byte arrays.
It is enough for me since I need to keep Long Raws in oracle and Blobs in DB2 and their size don't exceed 250 KB.

It should be enough to convince my executives not to buy expensive Kodo licenses! :)

Thanks.


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.