We are using Hibernate 3.2.4, Jboss 4.0.4 GA, Oracle 10g, EJB 3
We are trying to store Blob into the database - but not all bytes are stored.
The blob is created out of an CipherInputStream (the stream is passed to a local method of an EJB).
The CipherInputStream is created (in the Web Teir) out of FileInputStream and Cipher objects.
Following is part of the local EJB method code:
public void addContent(Content content, CipherInputStream inputStream )throws DBException{
Blob blob = Hibernate.createBlob(inputStream, streamLength);
** Now write the blob into Oracle using Hibernate …
}
In the example we are running, the cipherd stream has 1104 bytes, but only the first 512 bytes of them are eventually stored in the database.
Some clues:
1) inputStream.available() returns 0.
2) When checking the number of bytes of the InputStream of the Blob, ( by reading all bytes of blob.getBinaryStream() ) we get the right number (1104)
3) If we create the Blob without passing the streamLength, e,g:
Blob blob = Hibernate.createBlob(inputStream);
a null will appear in the datatbase
4) If we pass the original FileInputStream to the created Blob all bytes are stored correctly.
Please help,
Eitan
**************************************************
The generated SQL:
insert into CONTENT_STORAGE (CONTENT_FILE, CONTENT_FILE_BIN, CREATION_TIMESTAMP, CONTENT_ID, VERSION) values (?, ?, ?, ?, ?)
The mapping file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<hibernate-mapping package=".......dms.contentmanager.model">
<class name="ContentStorage" table="CONTENT_STORAGE" >
<composite-id name="contentPrimaryKey" class="......dms.contentmanager.model.ContentPrimaryKey">
<key-property name="contentId" column="CONTENT_ID" type="string" length="255"></key-property>
<key-property name="version" column="VERSION" type="float" length="255"></key-property>
</composite-id>
<property name="contentFile" column="CONTENT_FILE" type="clob" not-null="false"></property>
<property name="contentFileBin" column="CONTENT_FILE_BIN" type="blob" not-null="false"></property>
<property name="creationTimestamp" column="CREATION_TIMESTAMP" type="timestamp"></property>
</class>
</hibernate-mapping>
|