-->
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.  [ 6 posts ] 
Author Message
 Post subject: Blobs may not be accessed after serialization
PostPosted: Fri Oct 07, 2005 7:38 am 
Newbie

Joined: Sun Feb 29, 2004 4:18 pm
Posts: 7
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.1 beta 5


Full stack trace of any exception that occurs:
Blobs may not be accessed after serialization
Stack Trace:

* org.hibernate.lob.SerializableBlob.getWrappedBlob(SerializableBlob.java:23)
* org.hibernate.lob.SerializableBlob.getBinaryStream(SerializableBlob.java:39)
* nl.huib.swiet.dao.impl.hibernate.ItemDAOImpl.saveOrUpdateItem(ItemDAOImpl.java:155)
* nl.huib.swiet.service.shop.ItemService.saveOrUpdateItem(ItemService.java:49)
* nl.huib.swiet.service.shop.ItemService$$FastClassByCGLIB$$b5303db5.invoke(<generated>)
* net.sf.cglib.proxy.MethodProxy.invoke(MethodProxy.java:149)
* org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(Cglib2AopProxy.java:661)
* org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:122)
* org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:57)
* org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144)
* org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:606)
* <censored>.ItemService$$EnhancerByCGLIB$$5dd13c60.saveOrUpdateItem(<generated>)

Name and version of the database you are using: MySQL 4.1

The generated SQL (show_sql=true):
Hibernate: update item set sold=?, width=?, height=?, thumbnail_medium=?, stock=?, name_nl=?, description_en=?, description_nl=?, name_en=?, buy_price=?, buy_date=?, in_shop=?, new_item=?, archived=?, sale_price=?, depth=? where id=?

Hi,

I have a problem updating a class which has a blob in it. During the operation I only loaded it via another object, so the blob probably isn't initialized (lazy is default). Then I set just a simple property on the object and call saveOrUpdate, which generates the above exception. I check the code and it seems the internal blob is null.
Could this be a bug, am I doing something wrong? I'm using annotations and I do not add anything to the blob getter, so I'm using defaults.

Regards,
Wouter


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 7:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
This is pretty much just a limitation of JDBC blobs. They may not be accessed outside the txn they were retrieved in.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 07, 2005 7:50 am 
Newbie

Joined: Sun Feb 29, 2004 4:18 pm
Posts: 7
So what are my options? I tried to Hibernate.initialize the object within the new transaction, but that didn't work. session.lock on it -no luck there-

Any hints/suggestions?
Wouter


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 20, 2005 5:59 pm 
Beginner
Beginner

Joined: Wed Sep 28, 2005 5:30 pm
Posts: 25
gavin wrote:
This is pretty much just a limitation of JDBC blobs. They may not be accessed outside the txn they were retrieved in.


Gavin, this seems to contradict what is written here: http://www.hibernate.org/250.html#A15

It explicitly states that classes containing SerializableBlobs can now be "detached, serialized, deserialized, and passed to merge()". So which is it? Does Session.merge() attach a new SerializableBlob to the enclosing object?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 20, 2005 6:26 pm 
Beginner
Beginner

Joined: Wed Sep 28, 2005 5:30 pm
Posts: 25
FYI: I just ran a local test and it seems to confirm what I suspected, Session.merge() creates a new SerializableBlob so you can use Blob properties across sessions or serialization.

If I don't use Session.merge() I get the same exception as wouterv reported. Gavin, can you please mention this in the documentation?


Top
 Profile  
 
 Post subject: SerializableBlob not so serializable after all in ejb3?
PostPosted: Mon Mar 31, 2008 3:27 pm 
Newbie

Joined: Thu Jan 04, 2007 3:48 pm
Posts: 5
hello again.

I felt compelled to re open this discussion as the last post was in 2005 and this is now 2008.

Using the serializableblob as described here:
http://www.hibernate.org/250.html#A15 and in this post, I am still getting the error,
Code:
java.lang.IllegalStateException: Blobs may not be accessed after serialization

I am using EJB3, Jboss 4.2, w/Oracle10g

Here is what is in my entity:
Code:
    @Lob
    @Basic(fetch=FetchType.LAZY)
    @Column(name="ART_FILE", nullable=false)
    public SerializableBlob getFile()
    {
        return file;
    }
    public void setFile(SerializableBlob file)
    {
        this.file = file;
    }


Here is my a snippet in the EJB that fails:
Code:
                SerializableBlob blob = (SerializableBlob)artFile.getFile();
               
                try
                {
                    if( (blob == null) || (blob.getBytes(0, new Integer(blob.length() + "")).length == 0 ) )
                    {
                        throw new InvalidArtFileException("The file size of the art file must be greater than 0 bytes!  ArtFile number " + i);
                    }
                }
                catch (SQLException e)
                {
                    logger.error("Caught SQL Exception while trying to determine the size of a file.",e);
                }


The above code that checks the length of the blob is running in a loop, thats the reason for the +i on the exception.

I am running a junit test case which is where the err occurs. My thoughts are that since this is a serializable blob that it shouldnt matter that I am running from junit to the ejb.

Here is the code used to put the blob into the entity (from the test case)

Code:
       File file=new File("C:\\Documents and Settings\\couldbeyou\\Desktop\\chicago\\IMAGE_129.jpg");
        FileInputStream fInSteam = new FileInputStream(file);
        BufferedInputStream bInputStream = new BufferedInputStream(fInSteam);
        ByteArrayOutputStream bOutputStream = new ByteArrayOutputStream();       
        int nextByte;
       
        while (( nextByte = bInputStream.read() ) != - 1)
        {
        bOutputStream.write(nextByte);
        }
        // Bob the builder builds a blob.       
        blob = (SerializableBlob)org.hibernate.Hibernate.createBlob(bOutputStream.toByteArray());
        }


this part seems to work fine, and if I remove the code from the EJB that checks the blob length and not null then I can see in the DB that it was persisted and a blob is present.

Any thoughts? Why am I getting this err using serializableblob? what can I do to not get this err using serializableblob?

_________________
2007-01-04 12:00:24,327 WARN com.yoofoo.GetSmartUser - Could not find any intelligent end-users


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