-->
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.  [ 2 posts ] 
Author Message
 Post subject: Blob may not be manipulated from creating session
PostPosted: Mon Jan 11, 2010 10:59 pm 
Newbie

Joined: Fri Apr 04, 2008 2:12 pm
Posts: 11
Hibernate version:
Hibernate v3.2.5

Name and version of the database you are using:
MySQL v5.0.45

JDBC: v5.1.10

Hi everyone,

I did do some searching in this forum, and went over the Hibernate docs a bit, but I couldn't find anything useful. Basically, when I try to commit my blobs, i get the 'java.lang.UnsupportedOperationException: Blob may not be manipulated from creating session'.
I was using Hibernate v3.2.5, MySQL v5.0.45, and JDBC v3.1.14, and everything was working fine. Then I decided to upgrade the JDBC drivers to v5.1.10 and got the UnsupportedOperationsException:
java.lang.UnsupportedOperationException: Blob may not be manipulated from creating session
at org.hibernate.lob.BlobImpl.excep(BlobImpl.java:104)
at org.hibernate.lob.BlobImpl.getBytes(BlobImpl.java:50)
at org.hibernate.lob.SerializableBlob.getBytes(SerializableBlob.java:35)
at com.mysql.jdbc.PreparedStatement.setBlob(PreparedStatement.java:3165)
at de.laliluna.example.Blobby.nullSafeSet(Blobby.java:65)
at org.hibernate.type.CustomType.nullSafeSet(CustomType.java:146)
at org.hibernate.persister.entity.AbstractEntityPersister.dehydrate(AbstractEntityPersister.java:2002)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2248)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2665)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:60)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at de.laliluna.example.TestConsoles.insertTables(TestConsoles.java:251)
at de.laliluna.example.TestConsoles.main(TestConsoles.java:141)

What am I doing wrong? Here is my code:

Code:
public class Consoles
{
    private long id;
    private byte blob[];
   
    public long getId()
    {
        return id;
    }

    public void setId(long id)
    {
        this.id = id;
    }
   
    public byte[] getBlob()
    {
        return blob;
    }

    public void setBlob(byte[] blob)
    {
        this.blob = blob;
    }
}


Code:
<?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 default-lazy="false">
<class name="de.laliluna.example.Consoles" table="CONSOLES" lazy="false">
  <id name="id" column="ID" type="long">
    <generator class="increment"/>
  </id>
  <property name="blob" column="INFO" type="de.laliluna.example.Blobby"/>
  <!--de.laliluna.example.Blobby is from http://www.hibernate.org/73.html-->
</class>
</hibernate-mapping>


Code:
someBlob = "My Long Blob that is not really " +
            "that long. I need to write more to test " +
            "Hibernate and how it can handle blobs.";
Consoles firstConsole = new Consoles():
firstConsole.setBlob(someBlob.getBytes());

InitSessionFactory init = null;
init = new InitSessionFactory();
Session session = null;
session = init.getInstance().getCurrentSession();
Transaction tx = null;
tx = session.beginTransaction();
session.save(firstConsole);
tx.commit(); <-- crashes here



Any help will be appreciated. Thanx


Top
 Profile  
 
 Post subject: Re: Blob may not be manipulated from creating session
PostPosted: Tue Jan 12, 2010 6:03 pm 
Newbie

Joined: Fri Apr 04, 2008 2:12 pm
Posts: 11
I looked at the stack trace again, and I remembered something I found in this forum. Unfortunately, I am unable search for that thread because this forum is down or slow? Anyway, the guide from https://www.hibernate.org/73.html (Mapping a Blob to a byte[]) has the method,

Code:
  public void nullSafeSet(PreparedStatement st, Object value, int index)
  throws HibernateException, SQLException
  {
    st.setBlob(index, Hibernate.createBlob((byte[]) value));
  }


I changed that to
Code:
  public void nullSafeSet(PreparedStatement st, Object value, int index)
  throws HibernateException, SQLException
  {
    st.setBytes(index, (byte[])value);
  }


and that works!! HTH someone else.


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