Hi,
i have problems retrieving a blob from a Oracle 9i database, see the fragments of the mapping files and the relevant hibernate log below.
There are no exceptions, and inserting the blob in the database works fine, the BLOB content in the database is o.k..
The retrieving of the blob works fine, too, but unfortunately the blob content is garbage.
Bye,
Jürgen
Hibernate version: 3.0.1
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="data">
<class name="AttachmentVO" table="attachments_new">
<id name="attachmentId" column="attachment_id" >
<generator class="sequence">
<param name="sequence">attachment_id_seq</param>
</generator>
</id>
<many-to-one name="message"
column="message_id" not-null="true"/>
<property name="fileName"
column="file_name" not-null="true"/>
<property name="fileData" lazy="true"
column="file_data" not-null="true"/>
</class>
</hibernate-mapping>
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- DB connection -->
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">URL</property>
<property name="connection.username">USER</property>
<property name="connection.password">PASSWORD</property>
<property name="jdbc.use_streams_for_binary">true</property>
<!-- other Hibernate settings -->
<property name="show_sql">true</property>
<!-- mapping files -->
<mapping resource="AttachmentVO.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Name and version of the database you are using:Oracle 9i, Oracle 10g thin driver
Debug level Hibernate log excerpt:[...]
Code:
08:00:54,834 [DEBUG] org.hibernate.loader.entity.EntityLoader: Static select for entity com.bmw.ehr.business.inbox.data.AttachmentVO: select attachment0_.attachment_id as attachment1_0_, attachment0_.message_id as message2_1_0_, attachment0_.file_name as file3_1_0_, attachment0_.file_data as file4_1_0_ from attachments_new attachment0_ where attachment0_.attachment_id=?
08:00:54,834 [DEBUG] org.hibernate.loader.entity.EntityLoader: Static select for entity com.bmw.ehr.business.inbox.data.AttachmentVO: select attachment0_.attachment_id as attachment1_0_, attachment0_.message_id as message2_1_0_, attachment0_.file_name as file3_1_0_, attachment0_.file_data as file4_1_0_ from attachments_new attachment0_ where attachment0_.attachment_id=?
08:00:54,844 [DEBUG] org.hibernate.loader.entity.EntityLoader: Static select for entity com.bmw.ehr.business.inbox.data.AttachmentVO: select attachment0_.attachment_id as attachment1_0_, attachment0_.message_id as message2_1_0_, attachment0_.file_name as file3_1_0_, attachment0_.file_data as file4_1_0_ from attachments_new attachment0_ where attachment0_.attachment_id=? for update
08:00:54,844 [DEBUG] org.hibernate.loader.entity.EntityLoader: Static select for entity com.bmw.ehr.business.inbox.data.AttachmentVO: select attachment0_.attachment_id as attachment1_0_, attachment0_.message_id as message2_1_0_, attachment0_.file_name as file3_1_0_, attachment0_.file_data as file4_1_0_ from attachments_new attachment0_ where attachment0_.attachment_id=? for update nowait
[...]
Code:
08:00:55,465 [DEBUG] org.hibernate.SQL: insert into attachments_new (message_id, file_name, file_data, attachment_id) values (?, ?, ?, ?)
Hibernate: insert into attachments_new (message_id, file_name, file_data, attachment_id) values (?, ?, ?, ?)
08:00:55,465 [DEBUG] org.hibernate.jdbc.AbstractBatcher: preparing statement
08:00:55,465 [DEBUG] org.hibernate.persister.entity.BasicEntityPersister: Dehydrating entity: [com.bmw.ehr.business.inbox.data.AttachmentVO#890]
08:00:55,465 [DEBUG] org.hibernate.type.LongType: binding '900' to parameter: 1
08:00:55,465 [DEBUG] org.hibernate.type.StringType: binding 'testname.txt' to parameter: 2
08:00:55,465 [DEBUG] org.hibernate.type.BinaryType: binding 'e4e1f4e1' to parameter: 3
08:00:55,465 [DEBUG] org.hibernate.type.LongType: binding '890' to parameter: 4
08:00:55,465 [DEBUG] org.hibernate.jdbc.AbstractBatcher: Adding to batch
08:00:55,465 [DEBUG] org.hibernate.jdbc.AbstractBatcher: Executing batch size: 1
08:00:55,465 [DEBUG] org.hibernate.jdbc.AbstractBatcher: success of batch update unknown: 0
08:00:55,465 [DEBUG] org.hibernate.jdbc.AbstractBatcher: about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
08:00:55,465 [DEBUG] org.hibernate.jdbc.AbstractBatcher: closing statement
[...]
Code:
08:00:55,535 [DEBUG] org.hibernate.loader.Loader: loading collection: [com.bmw.ehr.business.inbox.data.MessageVO.attachments#900]
08:00:55,535 [DEBUG] org.hibernate.jdbc.AbstractBatcher: about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
08:00:55,535 [DEBUG] org.hibernate.SQL: select attachment0_.message_id as message2___, attachment0_.attachment_id as attachment1___, attachment0_.attachment_id as attachment1_0_, attachment0_.message_id as message2_1_0_, attachment0_.file_name as file3_1_0_, attachment0_.file_data as file4_1_0_ from attachments_new attachment0_ where attachment0_.message_id=?
Hibernate: select attachment0_.message_id as message2___, attachment0_.attachment_id as attachment1___, attachment0_.attachment_id as attachment1_0_, attachment0_.message_id as message2_1_0_, attachment0_.file_name as file3_1_0_, attachment0_.file_data as file4_1_0_ from attachments_new attachment0_ where attachment0_.message_id=?
08:00:55,535 [DEBUG] org.hibernate.jdbc.AbstractBatcher: preparing statement
08:00:55,535 [DEBUG] org.hibernate.type.LongType: binding '900' to parameter: 1
08:00:55,575 [DEBUG] org.hibernate.jdbc.AbstractBatcher: about to open ResultSet (open ResultSets: 0, globally: 0)
08:00:55,575 [DEBUG] org.hibernate.loader.Loader: result set contains (possibly empty) collection: [com.bmw.ehr.business.inbox.data.MessageVO.attachments#900]
08:00:55,575 [DEBUG] org.hibernate.engine.CollectionLoadContext: uninitialized collection: initializing
08:00:55,575 [DEBUG] org.hibernate.loader.Loader: processing result set
08:00:55,575 [DEBUG] org.hibernate.loader.Loader: result set row: 0
08:00:55,575 [DEBUG] org.hibernate.type.LongType: returning '890' as column: attachment1_0_
08:00:55,575 [DEBUG] org.hibernate.loader.Loader: result row: EntityKey[com.bmw.ehr.business.inbox.data.AttachmentVO#890]
08:00:55,575 [DEBUG] org.hibernate.loader.Loader: Initializing object from ResultSet: [com.bmw.ehr.business.inbox.data.AttachmentVO#890]
08:00:55,575 [DEBUG] org.hibernate.persister.entity.BasicEntityPersister: Hydrating entity: [com.bmw.ehr.business.inbox.data.AttachmentVO#890]
08:00:55,575 [DEBUG] org.hibernate.type.LongType: returning '900' as column: message2_1_0_
08:00:55,575 [DEBUG] org.hibernate.type.StringType: returning 'testname.txt' as column: file3_1_0_
08:00:55,575 [DEBUG] org.hibernate.type.BinaryType: returning '80d48081818c808080818080808180808080d6398080a96a8080a9698084808480808080808080808080808080808080808080808b91f2be851c8080808080808080808080808080808080808080a969838080fa8080' as column: file4_1_0_
08:00:55,575 [DEBUG] org.hibernate.type.LongType: returning '900' as column: message2___
08:00:55,575 [DEBUG] org.hibernate.loader.Loader: found row of collection: [com.bmw.ehr.business.inbox.data.MessageVO.attachments#900]
08:00:55,575 [DEBUG] org.hibernate.engine.CollectionLoadContext: reading row
08:00:55,575 [DEBUG] org.hibernate.type.LongType: returning '890' as column: attachment1___
08:00:55,575 [DEBUG] org.hibernate.event.def.DefaultLoadEventListener: loading entity: [com.bmw.ehr.business.inbox.data.AttachmentVO#890]
08:00:55,575 [DEBUG] org.hibernate.event.def.DefaultLoadEventListener: entity found in session cache
08:00:55,575 [DEBUG] org.hibernate.event.def.DefaultLoadEventListener: attempting to resolve: [com.bmw.ehr.business.inbox.data.AttachmentVO#890]
08:00:55,575 [DEBUG] org.hibernate.event.def.DefaultLoadEventListener: resolved object in session cache: [com.bmw.ehr.business.inbox.data.AttachmentVO#890]
08:00:55,575 [DEBUG] org.hibernate.loader.Loader: done processing result set (1 rows)