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