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: Error in inserting Blob to database :
PostPosted: Tue Apr 14, 2009 4:40 am 
Newbie

Joined: Wed Mar 25, 2009 10:12 pm
Posts: 4
Hibernate Version :2.9.5
IDE:NetBeans 6.5
Oracle:10g
Jar used:classes12.jar

I reverse engineered and created my hbm file and java files.

I have one table having a Blob field.Reverse mapping registered it as a serializible type.I can now insert data into it but cannot retrieve from it,It shows a Hibernate exception,invalid conversion required.

So I changed the type to Blob. and now I can read data from database but cannot insert.
The error I am getting is :Blob may not be manipulated from creating session

Before that editing I got cannot serialize error.

I tried UserTypes described in Hibernate.org. But got the same error.

Now what should I do to get rid of this issue.

My hbm file [snippet is]
Code:
   <property name="image" type="hibernateimaged.BlobType">
      <column name="IMAGE"/>
    </property>


Where BlobType is the class that implements UserType

The code which I am trying to execute
Code:
   public void saveImage(byte[] image) throws SQLException

    {
         
          SessionFactory factory = HibernateUtil.getSessionFactory();
          Session session = factory.getCurrentSession();
          Blob myimage=Hibernate.createBlob((byte[]) image);
          myimage.setBytes(1, image);
          session.beginTransaction().begin();

          TestBlob bilobe=new TestBlob();  //This is my mapped Class
          bilobe.setId((long)1028);
          bilobe.setFileName("FileName");
          bilobe.setUsername("UserName");
          bilobe.setTimestamp(new Date(1,1,1993));
          bilobe.setImage(image);
          session.save(bilobe);
          session.getTransaction().commit();

    }
[/code]


Top
 Profile  
 
 Post subject: I solved the problem
PostPosted: Tue Apr 14, 2009 11:08 am 
Newbie

Joined: Wed Mar 25, 2009 10:12 pm
Posts: 4
The hbm file was kept intact

And this code is to insert multimedia to database

Code:
        byte[] oneByte = {1};
        bilobe.setImage(Hibernate.createBlob(oneByte));
        session.save(bilobe);
        session.flush();
        session.refresh(bilobe, LockMode.UPGRADE);
        Blob field=bilobe.getImage();
        field=Hibernate.createBlob(image);
        bilobe.setImage(field);
        session.getTransaction().commit();


Everything works fine and data is inserted

Used commons File Upload and Struts 1.2.9


Thanks


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.