hi guys
how do you store BLOBs in Oracle ?
I have managed to store a CLOB (>4kb) and I thought the same idea (as decribed here
http://www.hibernate.org/56.html) would work with BLOBs, but it doesn't. This code appears to be writing something into the BLOB, but nothing gets written into the database. This code creates a new row, but BLOB is empty.
I am using Hibernate 3.2, Oracle 10g XE and thin jdbc driver.
Code:
Report newReport = new Report(item.getName(), Hibernate.createBlob(new byte[]{0}) , Hibernate.createBlob(new byte[]{0}) );
session.save(newReport);
session.flush();
session.refresh(newReport, LockMode.UPGRADE);
SerializableBlob blob = (SerializableBlob) newReport.getReport();
InputStream isr = item.getInputStream();
OutputStream os = blob.setBinaryStream(0L);
while(true)
{
byte[] buff = new byte[1024];
int read = isr.read(buff,0,buff.length);
if (read!=-1)
{
os.write(buff,0,read);
} else
{
break;
}
};
os.flush();
os.close();
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">
<!-- Generated 2006.30.11 23:44:24 by Hibernate Tools 3.2.0.beta8 -->
<hibernate-mapping>
<class name="persistence.domain.objects.Report" table="REPORT" schema="WMSDB">
<id name="name" type="string">
<column name="NAME" length="100" />
<generator class="assigned" />
</id>
<property name="jasper" type="blob">
<column name="JASPER" />
</property>
<property name="report" type="blob">
<column name="REPORT" />
</property>
</class>
</hibernate-mapping>