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.  [ 12 posts ] 
Author Message
 Post subject: Hibernate 3.0.5 and Oracle 9 BLOBs... anything different?
PostPosted: Thu Jul 28, 2005 11:29 am 
Newbie

Joined: Thu Jul 28, 2005 11:22 am
Posts: 9
Hibernate version:
3.0.5

Name and version of the database you are using:
Oracle 9i


Hi there!

I'm trying to work with Oracle BLOBs and Hibernate 3.0.5. I've seen several of the technical documents on the subject here, threads, etc. But they all seem to be geared for Hibernate 2.x releases.

Is anything different in the approach I need to do to get Oracle BLOBs to work in Hibernate 3? Any provements? Can someone throw me a bone here? :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 11:18 am 
Newbie

Joined: Thu Jul 28, 2005 11:22 am
Posts: 9
To anyone else who might be interested...

I found that Spring 1.2.2 does a very good job of handling Oracle LOBs with Hibernate so I used their custom type and all is good.

Thanks for reading tho...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 11:44 am 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
hibernate 3.0 and oracle jdbc 10g (work with oracle 9i) wokr with blob
It is easy for use, for example :
define column in table blob

mapping for blob :
Code:
<property name="blobProperty" type="blob" column="BLOB_COLUMN" />


and in java define property

private java.sql.Blob blobProperty

It work fine

regards


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 12:07 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
ElPapa wrote:
To anyone else who might be interested...

I found that Spring 1.2.2 does a very good job of handling Oracle LOBs with Hibernate so I used their custom type and all is good.


Yes, but be aware that their implementation does not work with appserver connection pools, which is why we do not have any such functionality built into Hibernate.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 1:55 pm 
Newbie

Joined: Thu Jul 28, 2005 11:22 am
Posts: 9
gavin wrote:
ElPapa wrote:
To anyone else who might be interested...

I found that Spring 1.2.2 does a very good job of handling Oracle LOBs with Hibernate so I used their custom type and all is good.


Yes, but be aware that their implementation does not work with appserver connection pools, which is why we do not have any such functionality built into Hibernate.


Gavin, can you please elaborate on this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 2:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
As i understand, it requires casting to Oracle-specific APIs, which is not possible if you have a Connection proxied by the connection pool.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 2:02 pm 
Newbie

Joined: Thu Jul 28, 2005 11:22 am
Posts: 9
snpesnpe wrote:
hibernate 3.0 and oracle jdbc 10g (work with oracle 9i) wokr with blob
It is easy for use, for example :
define column in table blob

mapping for blob :
Code:
<property name="blobProperty" type="blob" column="BLOB_COLUMN" />


and in java define property

private java.sql.Blob blobProperty

It work fine

regards


OK.. but getting data *into* the blob is the challenge.. Are you saying I don't need a custom type, just call Hibernate.createBlob() with whatever I stream the information into? I found that to be problematic..


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 2:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
ElPapa wrote:
OK.. but getting data *into* the blob is the challenge.. Are you saying I don't need a custom type, just call Hibernate.createBlob() with whatever I stream the information into? I found that to be problematic..


From: http://hibernate.org/56.html


Code:
s = sf.openSession();
tx = s.beginTransaction();
foo = new Foo();
foo.setClob( Hibernate.createClob(" ") );
s.save(foo);
s.flush();
s.refresh(foo, LockMode.UPGRADE); //grabs an Oracle CLOB
oracle.sql.CLOB clob = (oracle.sql.CLOB) foo.getClob();
java.io.Writer pw = clob.getCharacterOutputStream();
pw.write(content);
pw.close();
tx.commit();
s.close();


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 3:02 pm 
Newbie

Joined: Thu Jul 28, 2005 11:22 am
Posts: 9
Heh.. that brings me back to my original question... :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 5:36 pm 
Expert
Expert

Joined: Sat Jun 12, 2004 4:49 pm
Posts: 915
Quote:
OK.. but getting data *into* the blob is the challenge.. Are you saying I don't need a custom type, just call Hibernate.createBlob() with whatever I stream the information into? I found that to be problematic..


yes

I have mapping like one in my post and read and save image like this :

Code:
public void testRead() throws IOException, SQLException {
       String id = "2";
        //OrgZap orgZap = (OrgZap) getSession().get(OrgZap.class, id);
        OrgZapImage orgZapImage = (OrgZapImage) getSession().get(
                OrgZapImage.class, id);
       
        InputStream input = getClass().getResourceAsStream(
                "/images/maradona_thumb.gif");
        byte bytes[] = new byte[input.available()];
       
        int i = input.read(bytes);
        Blob readBlob = orgZapImage.getImage();
        int len = (int) readBlob.length();
        byte[] readBytes = readBlob.getBytes(1, len);
       
        assertTrue("blob and read blob are same",bytes.length == readBytes.length);
        for (int j=0;j<bytes.length;j++)
              assertTrue("test byte " + j,bytes[j] == readBytes[j]);
    }

    public void testSave() throws IOException, SQLException {
       String id = "2";
        OrgZap orgZap = (OrgZap) getSession().get(OrgZap.class, id);
        OrgZapImage orgZapImage = (OrgZapImage) getSession().get(
                OrgZapImage.class, id);
        if (orgZapImage != null)
            getSession().delete(orgZapImage);
        orgZapImage = new OrgZapImage();
        InputStream input = getClass().getResourceAsStream(
                "/images/maradona_thumb.gif");
        byte bytes[] = new byte[input.available()];
       
        int i = input.read(bytes);
       
        Blob blob = Hibernate.createBlob(bytes);

        orgZapImage.setId(orgZap.getId());
        orgZapImage.setImage(blob);
        Transaction t = getSession().beginTransaction();
        getSession().save(orgZapImage);
        t.commit();
        getSession().evict(orgZapImage);
        OrgZapImage orgZapImage1 = (OrgZapImage) getSession().get(
                OrgZapImage.class, orgZap.getId());
        Blob readBlob = orgZapImage1.getImage();
        int len = (int) readBlob.length();
        byte[] readBytes = readBlob.getBytes(1, len);
       
        assertTrue("blob and read blob are same",bytes.length == readBytes.length);
    }


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 29, 2005 10:11 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
springs stuff actually does work with app server connection pools. They have this interface (the name escapes me) that extracts the underlying Connection from the app server-supplied proxy.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 30, 2005 12:33 am 
Newbie

Joined: Thu Jul 28, 2005 11:22 am
Posts: 9
steve wrote:
springs stuff actually does work with app server connection pools. They have this interface (the name escapes me) that extracts the underlying Connection from the app server-supplied proxy.


Correct you are. I figured that out after more testing today....


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 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.