-->
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.  [ 1 post ] 
Author Message
 Post subject: How to store Oracle BLOB ?
PostPosted: Thu Nov 30, 2006 6:55 pm 
Newbie

Joined: Tue May 17, 2005 8:39 am
Posts: 14
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>


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

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.